-2

I am encountering an issue to save/ create the file using java.

java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method) ~[na:1.7.0_79]

My environment is using Linux but having a mount on Windows (The place where I try to store the file). It will hit everytime I tried to create when the filename having a chinese characters.

Could this happen because of encoding between Linux and Windows difference?

When I tried running and storing in similar OS (run apps in Linux, storing in Linux, same thing for windows) it run smoothly.

Any help is very appreciated.

The code i used to create the file

        File imgPath = new File(fullpath.toString());

        if (!imgPath.exists()){                 
            FileUtils.forceMkdir(imgPath);
            imgPath.setWritable(true, false);
        }

        fullpath.append(File.separator).append(fileName);

        outputStream = new FileOutputStream(new File(fullpath.toString()));

Thanks a lot.

Mihir
  • 572
  • 1
  • 6
  • 24
zxcvc
  • 345
  • 1
  • 16
  • 1
    Its not a typo but os cross platform issue. I have mentioned on above. I am running my apps on linux while trying to save it on windows mount. Have checked the path, permission. It works fine when filename doesnt have chinese characters. – zxcvc May 24 '17 at 11:03

1 Answers1

1

Note: I'm a fairly new user and can't comment directly yet (only on my questions and answers so far), so I'm posting this as an answer.

Windows uses UTF-16 while Linux uses UTF-8; (considering that you haven't installed anything extra to change anything yet) UTF-8 and UTF-16 support the same range of characters. However, I remember correctly, it had something to do with memory (UTF-8 starts at 8 bits and UTF-16 starts at 16?). Regardless, they're stored/ read a little differently. And then, InputStreamReader converts characters from their external representation in the specified encoding to the internal representation. It's mentioned in this stackoverflow post (Difference between UTF-8 and UTF-16?) about the exact way it's done in bytes. They're the same for the basics, but different for others, like Chinese characters. would suggest looking for solutions along that line (I have to get to class!). I could be entirely wrong, but this is probably a good starting place. Good luck.

shanshine
  • 144
  • 9
  • sorry for slow response. its like what u said but even on UTF-16 there is a simplified chinese and traditional chinese. I have successfully to save the file but the filename is totally different because what the actual filename is using simplified version. – zxcvc May 31 '17 at 03:41