wood burning stoves
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating files using Class file" Watch "Creating files using Class file" New topic

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
} catch (IOException e) {

why it doesnot create file at C:\ drive
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

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

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


Sampath Kumar

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
jQuery in Action, 3rd edition