• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creation of a new file throws IOException

 
Sweety C Sanford
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

public class Test {

public static void main(String... args) throws Exception {
File myDir = new File("test");
// myDir.mkdir();
File myFile = new File(
myDir, "test.txt");
myFile.createNewFile();
}

}

What is the mistake i'm doing here?
It throws me the following exception :

Exception in thread "main" java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at Files.Test.main(Test.java:11)

Thanks,
Jesu
 
Sweety C Sanford
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have modified my code like this

public class Test {

public static void main(String... args) throws Exception {
File myDir = new File("test");
myDir.mkdir();
File myFile = new File(myDir,"test1");
myFile.createNewFile();
}

}

Even now Cribbing
 
Sweety C Sanford
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OOPs The mistake i was doing is i have not given the filname with extension.
The below code executes perfect.

import java.io.File;
public class Test {

public static void main(String... args) throws Exception {
File myDir = new File("test");
myDir.mkdir();
File myFile = new File("myDir","test1.txt");
myFile.createNewFile();
}

}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!