java read local file failed FileNotFoundException ultimate solution to solve a series of related abnormalities

This article is mainly to solve resolve not operate the local file to display the folder path is invalid or no rights and other issues encountered in work or study

 First on a map

As shown above, my file name path is obviously correct but it shows that the file does not exist and some people may file delimiters are not used to this in order to prevent tangled on again on this issue on a

So that when you manipulate the file will be incorrect report


Just to name two most frequent error message will be written about can not read detailed error analysis input file in the next blog post

Under normal circumstances we manipulate files as long as the file path name is correct then it is surely no problem but !!!!

Just upload the picture has been explained clearly the right path to a question that why is it being given black question marks ????

But since we, as a programmer should firmly believe that now has a bug so sure our code is not the person hung up the program it will not sell Meng coquetry will not lie so the code above there is definitely a problem

Baidu found in the search of solutions to the basic Google after you look at your path is right that you do not use another slash your letter case does not


Since I wrote a blog that is certainly looking to continue to see on the map where the problem then let's see step by step



At first I encountered such a situation I want to collapse but still smiling down measure

Since there right then it appeared once again that the code is problematic

Originally, I was ready to implement the process of looking through the entire file of the class then I thought would not be a problem here continue on map

The problem probably came out here now intelligent development tools deceive our eyes while we looked at the two strings are identical is not really the

Then we went to see the process of the implementation of the class

Although shown two strings are the same, but looking at the beginning or demo2 actually have characters do not know in the end what is shown in Figure

Finally, what I also find the root cause of the problem in fact most of this article talking about the problems in local test stage because you will definitely test the local manually enter the address of a file and then issue the local implementation of the results of the test method this time will Appeared

Although the file manually to address me but I was so copied (the system is win10)

Programmers are lazy save each file properties are safe in absolute path of the file to copy it directly to me in the past to modify the delimiters to OK it is precisely because this step led to the emergence of the above! If we go left the right to copy this path is not the problem

But if favorably right to left and pull a good length (that is, start and tap and hold the mouse at the end of the file name does not move hard pull to the left) will be a problem that can be seen in the console:


The first is from left to right copy the second copy from right to left and that tugged can be seen in the console there is a garbled characters appear now that this is copied to the invisible character intelligent text editing tool (Note: this effect can be seen only in the console this non-smart editor)

That's all for this article, we hope to help



Published 15 original articles · won praise 21 · views 30000 +

Guess you like

Origin blog.csdn.net/q690080900/article/details/78499519