Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Here is My WriteFile

WriteFile.writeFile(str, "./test/my.html");

And writeFile() method code

public static void writeFile(String content, String fileName)
  {
    try
    {
      File file = new File(fileName);
      if (!file.exists()) {
        file.createNewFile();
      }
      FileWriter fw = new FileWriter(file.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);
      bw.write(content);
      bw.close();
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }

This Code Working fine With Windows but in Linux I am getting below exception

java.io.IOException: No such file or directory
    at java.io.UnixFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(File.java:1006)
    at org.sewa.util.WriteFile.writeFile(WriteFile.java:25)
share|improve this question
 
Maybe it's case related. Windows is not case-sensitive, while Linux is. –  broncoAbierto yesterday
 
I think it should help link –  mic4ael yesterday
 
@broncoAbierto Windows is not case-sensitive by default. –  m0skit0 yesterday
add comment

1 Answer

Behavior of createNewFile is the same in Windows and Linux, so most likely the path of the file you're specifing exists in Windows while it does not in Linux. In your example, test/ directory does not exist in Linux in the directory where you're executing the program. If you want to create the whole path, see File#mkdirs.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.