Disk Reader Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kid Programmer
    New Member
    • Mar 2008
    • 176

    #1

    Disk Reader Error

    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.FileNot FoundException: rawData.txt (No such file or directory)
    at java.io.FileInp utStream.open(N ative Method)
    at java.io.FileInp utStream.<init> (FileInputStrea m.java:106)
    at java.util.Scann er.<init>(Scann er.java:621)
    at readandwrite.Ma in.main(Main.ja va:26)

    This is my code:
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package readandwrite;
    
    /**
     *
     * @author Ned
     */
    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.PrintStream;
    
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) 
            // TODO code application logic here
            
            throws FileNotFoundException {
                Scanner diskScanner = new Scanner(new File("rawData.txt"));
                PrintStream diskWriter = new PrintStream("cookedData.txt");
                double unitPrice, quantity, total;
                
                unitPrice = diskScanner.nextDouble();
                quantity = diskScanner.nextInt();
                
                total = unitPrice * quantity;
                
                diskWriter.println(total);
                
                
            }
        }
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    Originally posted by Kid Programmer
    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.FileNot FoundException: rawData.txt (No such file or directory)
    at java.io.FileInp utStream.open(N ative Method)
    at java.io.FileInp utStream.<init> (FileInputStrea m.java:106)
    at java.util.Scann er.<init>(Scann er.java:621)
    at readandwrite.Ma in.main(Main.ja va:26)

    This is my code:
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package readandwrite;
    
    /**
     *
     * @author Ned
     */
    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.PrintStream;
    
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) 
            // TODO code application logic here
            
            throws FileNotFoundException {
                Scanner diskScanner = new Scanner(new File("rawData.txt"));
                PrintStream diskWriter = new PrintStream("cookedData.txt");
                double unitPrice, quantity, total;
                
                unitPrice = diskScanner.nextDouble();
                quantity = diskScanner.nextInt();
                
                total = unitPrice * quantity;
                
                diskWriter.println(total);
                
                
            }
        }
    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?

    Comment

    • Kid Programmer
      New Member
      • Mar 2008
      • 176

      #3
      Originally posted by sukatoa
      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!

      Comment

      Working...