• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io.WinNTFileSystem.createFileExclusively

 
Jalli Venkat
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check for existence==>false
java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at FileIO1.main(FileIO1.java:13)
Check for existence==>false

When I trying to run following code

File f1 = new File("D:\\TestFile.txt");
System.out.println("Check for existence==>"+f1.exists());
try {
f1.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

I getting above error message about "java.io.IOException: Access is denied". Can anybody help me in this?
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you see any security manager related strings in the exception trace..

like.. at java.lang.SecurityManager.checkPermission

Can you post the complete exception traces ?
 
Rob Spoor
Sheriff
Pie
Posts: 20559
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you create files in D: from other programs? You may simply have no rights to write to that folder.
 
Jalli Venkat
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No i didnt get any security related messages, below is the message coming after compilation of program


java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at FileIO1.main(FileIO1.java:13)
Check for existence==>false
 
Maneesh Godbole
Saloon Keeper
Posts: 11073
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can answer Rob's question, it will throw some light on the problem
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't sound like a "beginning Java" question. Moving to "general computing."
 
Mohammad Taslim
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taslim(From Pune)-


This might help you:-

If You have folder structure:-
C:\temp\File.java
And you are trying to create a new file (named same as the folder name File.java) at the same location C:\temp\

File myFile = new File("C://temp/" , "File.java");
myFile.createNewFile();

It will throw you this error:-

C:\temp\File.java
java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:850)
at com.java.InputOutput.file.FileMainClass.filenamepath(FileMainClass.java:23)
at com.java.InputOutput.file.FileMainClass.main(FileMainClass.java:55)






 
Nafis Akhtar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try{
boolean isCreated = false;
File file = new File("D:\\myFile.txt ");
System.out.println(file.exists());
isCreated = file.createNewFile();
System.out.println(isCreated);
System.out.println(file.exists());
}catch(IOException e){
e.printStackTrace();
}

Hope it will work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic