View the step-by-step solution to:

So for the code below, where do I save the file "numbers.

So for the code below, where do I save the file "numbers.txt" so that the program can find the file and it stops saying "file does not exist"


_________________________________________________________________________________________________________________


import java.io.File;


import java.io.FileNotFoundException;


import java.util.Scanner;


public class FileIntegersCount {


public static void main(String[] args) throws FileNotFoundException {


String fileName="D:\numbers.txt";


File file = new File(fileName);


if(file.exists()){


Scanner scan = new Scanner(file);


int count = 0;


while(scan.hasNextInt()) {


count++;


System.out.println(scan.nextInt());


}


scan.close();


System.out.println("Number of integers read: "+count);


} else {


System.out.println("File does not exist");


}


}


}

Top Answer

Output: 1 2 3 4 5 6 7 8 9... View the full answer

filelocationandfilename.PNG

1 comment
  • any doubt ask me
    • Student_manishjaiswal
    • May 02, 2018 at 6:47pm

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online