JAVA: IO new File(filename) throwing "Can't read input file!"
I'm trying to create a file from one server to another. Server A executes script which needs to create a file one server B. Server A has a script that creates folder without issues (no permission denied or anything) and call the following code after creating the folder:
byte[] btDataFile = new sun.misc.BASE64Decoder().decodeBuffer(base64);
File of = new File("driverLetter:\folder_path\filename.png");
FileOutputStream osf = new FileOutputStream(of);
osf.write(btDataFile);
osf.flush();
"base64" is a base64 string representation of a png image which I need 开发者_如何学编程to create as a file. The value of the string is quite long so I can't post it in here but it's there, not empty, not null, it has a value. But the code throws the error:
"Can't read input file!"
Why can the script read the "input file"? Thanks
Use forward slashes in your file path. Or escape backslashes with \\
.
You need to use an escape character since the backslash is reserved by java. Try a double backslash like this
File of = new File("driverLetter:\\folder_path\\filename.png");
It also suggested to use
File.separator
精彩评论