This discussion is archived
3 Replies Latest reply: Aug 7, 2008 11:04 PM by 807589 RSS

how to writing into file with known partial path of it

807589 Newbie
Currently Being Moderated
Hi All,

I am writing a java application. This contains some subfolders to be created like lib, bin... when i unzip the application.

I will be writing into some files under these directories programatically when this application was run.

My problem is, the zip file can be unzipped at any folder in system and I wont be knowing the exact file path....

For ex: If zip file was unzipped in C:\myData, after that it will create sub folders like
C:\myData\lib, C:\myData\bin.....

From programatically i wont be knowing the exact file path in bin folder to write the data.
How can I solve this problem? can someone help me here?

I wont know the absolute path, but i know the partial path of file like it will be in lib folder...

Please help me

Thanks....
  • 1. Re: how to writing into file with known partial path of it
    807589 Newbie
    Currently Being Moderated
    The simplest way is to prompt the user for the directory you need to write the files.
    You could use the directory where the classes come from as basis for finding this dir.
    Any other approach is likely to be a bit random.
  • 2. Re: how to writing into file with known partial path of it
    807589 Newbie
    Currently Being Moderated
    No need of full path required relative path is sufficient for it.

    e.g. if you want to write file at lib/my_file.txt

    then you can use
     new FileOutputStream("lib/my_file.txt");
  • 3. Re: how to writing into file with known partial path of it
    807589 Newbie
    Currently Being Moderated
    Hai,

    As long as I am running it from eclipse and making those sub folders required, its working fine.

    But how to make it work from non-eclipse environment?

    Basically unzipping my application will contain config, bin and lib folders. Lib folder contains the jar file created from the application in eclipse. I will be creating, reading and writing into some text files in config folder.

    Please help me.....

    I have written bat file to run this application. Even in that bat file also, I need to specify all the jar files path. But this application can be copied anywhere and even I dont know the location of it...

    How we will be handling these situations in JAVA generally???

    Thanks....