Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating files using Class file

 
mukki pandey
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
class Writer1 {
public static void main(String[] args) {
try { // warning: exceptions possible
boolean newFile = false;
File file = new File("C:\fileWrite1.txt");System.out.println(file.exists()); // look for a real file
newFile = file.createNewFile(); // maybe create a file!
System.out.println(newFile); // already there?
System.out.println(file.exists()); // look again
System.out.println(file.getPath());
} catch (IOException e) {
}
}
}

why it doesnot create file at C:\ drive
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does this have to do with SCJP ?

Have a look at your output for hints to solving the problem.
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here's the change:
File file = new File("C:\\fileWrite1.txt");

Regards,
Vishwa
 
Sampath Kumar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try replacing File file = new File("C:\fileWrite1.txt"); with File file = new File("C:/fileWrite1.txt");. you will get the file in C:\
 
mukki pandey
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys its working now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic