Reputation: 17
I am trying to read a file from my computer but it says java.io.FileNotFoundException (The system cannot find the file specified)
System.out.println("READING FILE");
File file = new File("Testing.txt"); //Reading file from E
FileInputStream in = null;
BufferedInputStream buff = null;
DataInputStream data= null;
String Line=""; // declare a string
try
{
in = new FileInputStream(file); // pick up the file
buff = new BufferedInputStream(in);
data = new DataInputStream(buff);
while (data.available() != 0)
{ // Read the file line by line till it reaches the end of file
Line=Line+data; // concatenate line into string
System.out.println(data.readLine()); // print line by line
}
} catch (IOException e)
{
e.printStackTrace();
}
Upvotes: 0
Views: 146
Reputation: 458
if you use windows try:
File file = new File("e:/Testing.txt");
(that means: use slash / instead of backslash \ )
Upvotes: 1
Reputation: 1
Where is the path of Testing.txt ???
File file = new File("Testing.txt"); //Reading file from E
Here java You are reading from out of src path if the file is in src you should modify the path
File file = new File("src/Testing.txt"); //Reading file from E
And another solution is enter the full path of file
Upvotes: 0
Reputation: 796
File file = new File("E:\\Testing.txt");
If you trying to access E this is one of the ways to do it
Upvotes: 1
Reputation: 160321
You need to either:
Upvotes: 0