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:
-
/*
-
* 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?