SYED SAAD ALI
SYED SAAD ALI

Reputation: 77

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.

Upvotes: 0

Views: 2602

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

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

Upvotes: 2

Related Questions