[Runtime]java.io.FileNotFoundException:weird character in String

Jia Weiぃも :

The weird symbol in the stack trace:

The weird symbol in the stack trace

Stacktrace:

java.io.FileNotFoundException: E: estilename.png (The filename, directory name, or volume label syntax is incorrect)

.java-encoded ANSI intended String"E:\test\filename.png"

1)compile no problem open with notepad doesn't see the weird symbol

end peacefully with

[wrote Filereadapp.class] [total 691ms]

-JDK:13.0.1,use Javafx &Apache Common IO as module

uses module path ,verbose,add module -options

compiled with batch file running commands,cd... & javac...

-Had seen the that some post suggest it's local win file sys job. or maybe the JDK job?

But I don't know how it works that changes the String itself. and how to fix it, prevent it?

2)StringBuilder->append all directory >append("e:").append("\test").append("\filename.png");

SB->String

FileOutputStream(Stringitself)

These are not the code itself!^ Just showing the flow of the real code.

Note on possible duplicate

I don't believe this is a duplicated post with any ?? char in Japanese word or anything.

Like file read/write using the relative path, as stated I gave absolute path unless the implementation of the absolute path is wrong.

Elliott Frisch :

In Java (and many other languages) \ is used to escape special characters (such as newline \n). Here you are escaping the letters t and f (\t is a tab and \f is a form-feed character) assuming your String looks like

String s = "e:\test\filename.png";

to fix that you can use any of

String s = "e:\\test\\filename.png";

or

String s = "e:/test/filename.png";

or

String s = "e:" + File.separator + "test" + File.separator + "filename.png";

And I'm sure there are a few other ways to write it too.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=389449&siteId=1