简体   繁体   中英

Reading particular line while reading text file in java

My question is i come up with a situation that i have a text file that contains following data including 15.

15 // first line

produce,3554,broccoli,5.99,1 //second line

i am using the following code to read the text in the file and printing its output.

try

{

File f = new File("filename.txt");


Scanner s= new Scanner(f);

s.hasNext();

String no = s.nextLine();
int num = Integer.parseInt(no);

System.out.println(num);// which prints number 15 only

}

now i want to read second line leaving first one which is "produce,3554,broccoli,5.99,1" in another variable and print it as i print 15 without using a loop . Is there any way that i can read second line.

String secondLine = s.nextLine();
System.out.println(secondLine);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM