Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Disk Reader Error

Question posted by: Kid Programmer (Familiar Sight) on May 15th, 2008 12:49 AM
Hello guys. I started learning about how to read information from disks and things.
I have a some code to start learning about it with. But when I run the code I get this error:

Exception in thread "main" java.io.FileNotFoundException: rawData.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.util.Scanner.<init>(Scanner.java:621)
at readandwrite.Main.main(Main.java:26)

This is my code:
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package readandwrite;
  7.  
  8. /**
  9.  *
  10.  * @author Ned
  11.  */
  12. import java.util.Scanner;
  13. import java.io.File;
  14. import java.io.FileNotFoundException;
  15. import java.io.PrintStream;
  16.  
  17. public class Main {
  18.  
  19.     /**
  20.      * @param args the command line arguments
  21.      */
  22.     public static void main(String[] args) 
  23.         // TODO code application logic here
  24.  
  25.         throws FileNotFoundException {
  26.             Scanner diskScanner = new Scanner(new File("rawData.txt"));
  27.             PrintStream diskWriter = new PrintStream("cookedData.txt");
  28.             double unitPrice, quantity, total;
  29.  
  30.             unitPrice = diskScanner.nextDouble();
  31.             quantity = diskScanner.nextInt();
  32.  
  33.             total = unitPrice * quantity;
  34.  
  35.             diskWriter.println(total);
  36.  
  37.  
  38.         }
  39.     }
sukatoa's Avatar
sukatoa
Needs Regular Fix
466 Posts
May 15th, 2008
12:54 AM
#2

Re: Disk Reader Error
Quote:
Hello guys. I started learning about how to read information from disks and things.
I have a some code to start learning about it with. But when I run the code I get this error:

Exception in thread "main" java.io.FileNotFoundException: rawData.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.util.Scanner.<init>(Scanner.java:621)
at readandwrite.Main.main(Main.java:26)

This is my code:
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package readandwrite;
  7.  
  8. /**
  9.  *
  10.  * @author Ned
  11.  */
  12. import java.util.Scanner;
  13. import java.io.File;
  14. import java.io.FileNotFoundException;
  15. import java.io.PrintStream;
  16.  
  17. public class Main {
  18.  
  19.     /**
  20.      * @param args the command line arguments
  21.      */
  22.     public static void main(String[] args) 
  23.         // TODO code application logic here
  24.  
  25.         throws FileNotFoundException {
  26.             Scanner diskScanner = new Scanner(new File("rawData.txt"));
  27.             PrintStream diskWriter = new PrintStream("cookedData.txt");
  28.             double unitPrice, quantity, total;
  29.  
  30.             unitPrice = diskScanner.nextDouble();
  31.             quantity = diskScanner.nextInt();
  32.  
  33.             total = unitPrice * quantity;
  34.  
  35.             diskWriter.println(total);
  36.  
  37.  
  38.         }
  39.     }


Base on your code, the rawData.txt should be at the same directory where your Main class exists...

The stackTrace says that the rawData.txt could not be found....
Have you check the directory of your .txt file?

Reply
Kid Programmer's Avatar
Kid Programmer
Familiar Sight
174 Posts
May 15th, 2008
01:10 AM
#3

Re: Disk Reader Error
Quote:
Base on your code, the rawData.txt should be at the same directory where your Main class exists...

The stackTrace says that the rawData.txt could not be found....
Have you check the directory of your .txt file?

That did it. Thanks!

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,846 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Java Forum Contributors