Results 1 to 3 of 3
  1. #1
    danoc93 is offline Member
    Join Date
    Apr 2012
    Posts
    37
    Rep Power
    0

    Default Current Directory is my user's folder...

    Hi, I have a program that creates a file with the name config.dat, but instead of placing it in the folder where jar is, it places it under my C:/Users/User folder, which is not something I want...

    The line I use is: 1. FileWriter file = new FileWriter ("config.dat");

    If I use: 2. FileWriter filewriter = new FileWriter ("/config.dat"); the file goes to C:/

    If I use: 3. String currentDir = new File(".").getAbsolutePath(); File file = new File(currentDir, "config.dat"); FileWriter filewriter = new FileWriter (file); I get the same problem of the first line...

    I read Java doesn't consider the currentdirectory as the one where the .class was run from, but the one that called the jvm...

    I don't know what to do, please help me a little bit.

  2. #2
    danoc93 is offline Member
    Join Date
    Apr 2012
    Posts
    37
    Rep Power
    0

    Default Re: Current Directory is my user's folder...

    I tried this:

    String ubicacion = new File(".").getCanonicalPath();

    File archivo = new File (ubicacion, "config.dat");

    Not working either, same thing than numer 1.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,239
    Rep Power
    19

    Default Re: Current Directory is my user's folder...

    Click here

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. changing current directory
    By flaca in forum New To Java
    Replies: 7
    Last Post: 03-06-2011, 02:50 AM
  2. Classpath problem for current directory
    By DerekRaimann in forum New To Java
    Replies: 10
    Last Post: 12-08-2010, 12:41 AM
  3. How to get Current Directory through File
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-05-2008, 10:14 AM
  4. How to get the current working directory in EJB?
    By sathish_2111 in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-19-2007, 04:24 PM
  5. How can i get current directory?
    By Ashley in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 01:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •