Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Creating files using Class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating files using Class file" Watch "Creating files using Class file" New topic
Author

Creating files using Class file

mukki pandey
Ranch Hand

Joined: Sep 22, 2008
Posts: 58
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

Joined: Feb 24, 2006
Posts: 6661
    
    5

What does this have to do with SCJP ?

Have a look at your output for hints to solving the problem.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
Hi,

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

Regards,
Vishwa


Blog
Sampath Kumar
Greenhorn

Joined: Sep 30, 2008
Posts: 4
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

Joined: Sep 22, 2008
Posts: 58
thanks guys its working now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating files using Class file
 
Similar Threads
Doubt:Sequence of the output
Transient /File Class
Files
Will FileReader create a new file?
File class questoin