Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

opening a file in FileWriter

  Asked By: Bryant    Date: May 26    Category: Java    Views: 883
  

When I try and write a file like this:

FileWriter fw=new FileWriter("settings.xml");
fw.write("asd");
fw.flush();
fw.close();

It dosnt write anything to the file but dosnt cause an
exception either. When I try this:

FileWriter fw=new FileWriter("/home/auser/settings.xml");
fw.write("asd");
fw.flush();
fw.close();

It works.

How do I get the path name of my current directory?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Jermaine Powell     Answered On: May 26

try "./settings.xml".....................

 
Answer #2    Answered By: Frank Butler     Answered On: May 26

It did not work........................

 
Answer #3    Answered By: Francis Riley     Answered On: May 26

You can use the System Property to get the user's current  working
directory, but I don't see anything wrong with your code. Both
versions worked when I tested them.

String currentDirectory = System.getProperty("user.dir");

 
Didn't find what you were looking for? Find more on opening a file in FileWriter Or get search suggestion and latest updates.




Tagged: