|
-
September 22nd, 2000, 04:26 PM
#1
Reading file lines into an Array of Strings
I need to be able to read a text file into an array of strings where each line has to go into a separate string.
I need to be able to read each line manipulate it and save it back to the same location in the file.
I wrote this code, but it does not read the line into the buf[]
public void updateScreen() {
DataInputStream dis = null;
try {
File trailFile = new File("D:\\RT\\CARRIER\\" + choiceControl1.getSelectedItem() + "\\TRAILER" + choiceControl2.getSelectedItem());//jTextField2.getText());
FileInputStream fis = new FileInputStream(trailFile);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
buf = new String[25]; //25 lines in the file
for(int j = 0; j < trailFile.length(); j++)
{
try {
for(int i = 0; i < 25; i++)
buf[i] = dis.readLine();
}
catch (Exception rr) {}
}
dis.close();
bis.close();
fis.close();
}
catch (Exception ee) {}
jTextField6.setText(buf[12]);
What am I doing wrong???
Thanks so much for any help.
Tami
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|