fatcodeguy
Programmer
Hi, I have a few problems. The first is reading lines from a file.
myfile.txt
this1;is1;my;1file1;ok1
this2;is2;my2;file2;ok2
this3;is3;my3;file3;ok3
this3;is3;my3;file3;ok3
---- code piece ---
public void parseFile(){
String str1,str2,str3,str4,str5,line;
BufferedReader dbms;
//file
try{dbms = new BufferedReader(new FileReader("dbms.cfg"
);}
catch(FileNotFoundException ee){}
try{line=dbms.readLine();}catch(IOException ee){}
StringTokenizer st = new StringTokenizer(line,";"
;
while(st.hasMoreTokens()){
str1=st.nextToken();
str2=st.nextToken();
str3=st.nextToken();
str4=st.nextToken();
str5=st.nextToken();
}
System.out.print(str1+" "+str2+" "+str3+" "+str4+" "+str5);
}//end method parseFile
--end of piece--
this will output --> this1 is1 my 1file1 ok1
I don't know how to read the other lines (and detect end of file). Additionally, I would like to know how to delete a specific line (say, the second line) without having to rewrite the whole file. Finally, I would like to append to the file.
Any help would be great! Thanks!!
myfile.txt
this1;is1;my;1file1;ok1
this2;is2;my2;file2;ok2
this3;is3;my3;file3;ok3
this3;is3;my3;file3;ok3
---- code piece ---
public void parseFile(){
String str1,str2,str3,str4,str5,line;
BufferedReader dbms;
//file
try{dbms = new BufferedReader(new FileReader("dbms.cfg"
catch(FileNotFoundException ee){}
try{line=dbms.readLine();}catch(IOException ee){}
StringTokenizer st = new StringTokenizer(line,";"
while(st.hasMoreTokens()){
str1=st.nextToken();
str2=st.nextToken();
str3=st.nextToken();
str4=st.nextToken();
str5=st.nextToken();
}
System.out.print(str1+" "+str2+" "+str3+" "+str4+" "+str5);
}//end method parseFile
--end of piece--
this will output --> this1 is1 my 1file1 ok1
I don't know how to read the other lines (and detect end of file). Additionally, I would like to know how to delete a specific line (say, the second line) without having to rewrite the whole file. Finally, I would like to append to the file.
Any help would be great! Thanks!!