Thursday, September 18, 2014

Reading from file in java?

Hi,
now suppose i have a file called >cool.txt< and it contains:
" ADDSTUDENT 12345 JOHN WILLIAMS "

MY CODE GOES LIKE THIS:

File inf = new File ("C:\\Users\\LENOVO\\Desktop\\cool.txt");
File outf = new File ("C:\\Users\\LENOVO\\Desktop\\JACK.txt");

Scanner in = new Scanner(inf);
PrintWriter out = new PrintWriter(outf);

;

String s = "";

String firstName ;
String lastName ;
int ID;

while(in.hasNext(. {
s = in.next();
if(s.equals("ADDSTUDENT". {

/*her i want to read the id number, first name and last name and save them to ID, firstName and lastName
respectively*/

}}

Read more: Reading from file in java?