• Register
1 vote
35 views

Problem:

I have started learning java a few days earlier. I was doing good so far except I git the error: java.io.FileNotFoundException: (The system cannot find the file specified)

I was trying to read a file from my system as an assignment but it’s not working in my case. I have got a very simple set code and I am attaching my code snippet below. Please, have a look and fix the error for me (if possible)

import java.io.*;
	public class Assignment{
	    public static void main(String[] args) throws IOException {
	        try {
	      MyReader reader = new MyReader(new FileReader("D:/my_text.txt"));
	      System.out.println(reader.readLine());
	    } catch (IOException e) {
	      System.out.println(e);
	    }
	 
	    }
	}

Thanks for your help, mate.

 

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

I haven’t found any problem in your code except your file location specification. Please write the file location like below except yours.

"D:\\my_text.txt"

This problem generally occurs due to the mismatch of the file name. The other possible problem could be the name of your source file and inside the FileReader() function name. Otherwise, it looks good.
Re-check them and fix them if you find any mismatch there. 

Thanks

13 9 6
94,260 points

Related questions

0 votes
1 answer 18 views
18 views
the system cannot find the file specified in java. I do not know the reason and I want a solution with an example in order to understand the topic and can address the problem. Thank you
asked Feb 5 ahmedadel9090 3.1k points
0 votes
1 answer 13 views
0 votes
1 answer 24 views
0 votes
1 answer 24 views
24 views
I'm wondering what I am doing wrong?
asked Jan 3 TeamScript 13.5k points
0 votes
1 answer 24 views
24 views
Problem: when I run, I get this error: C:\Users\User\Documents\Workspace\FileRead\hello.txt Error: hello.txt (The system cannot find the file specified) my FileRead.java and hello.txt where in the same directory that can be found in: C:\Users\User\Documents\Workspace\FileRead I'm wondering what I am doing wrong?
asked Dec 2, 2020 Mashhoodch 13k points
0 votes
1 answer 2 views
2 views
Problem: How to solve the java error, "the system cannot find the path specified java?"
asked 3 days ago sumaiya simi 23.4k points
0 votes
1 answer 6 views
6 views
Problem: I just need help to steer me in the right direction"java.io.ioexception: the system cannot find the path specified"any suggestion would be appreciated.
asked Apr 8 sumaiya simi 23.4k points
0 votes
1 answer 5 views
5 views
Problem: Please help me in differentiating what is i++ and ++i !
asked Mar 27 Madhav96 2.3k points
0 votes
0 answers 2 views
2 views
problem: why i get the error error the system cannot find the file specified.please help.
asked 2 days ago ashik 14.6k points
0 votes
2 answers 2 views
2 views
problem: help me to fix the problem [error 2] the system cannot find the file specified.
asked 2 days ago ashik 14.6k points