How to create a file in current directory?

by prajapatmanoj » Thu, 30 Apr 2009 02:05:51 GMT


Sponsored Links
 Hi

I am new to Android and creating my first application.

I want to create a file in the current directory. Basically I have a
file bundled with aplication package as raw resource. I want to make a
copy of this file in the current file. The reason to create copy in
current directory is that I want my file reading code in native java,
portable code.

To write a file in current directory I am doing following:

        String currentdir = System.getProperty("user.dir");
        String destination = currentdir + "test.txt";
        File fileCon = new File(destination);
        if( ! fileCon.exists() ){
                fileCon.createNewFile();
            }

But on createNewFile statement it is throwing IOException with
following message

java.io.IOException: Parent directory of file is not writable:
temp.txt

So my query is how can I create a file on current directory? The
location current directory is important here as I do not want to make
use of device specific hardcoded path or any Android API while reading
the file. This is so I want my file reading code portable.

Thanks

--~--~---------~--~----~------------~-------~--~----~



How to create a file in current directory?

by prajapatmanoj » Thu, 30 Apr 2009 02:05:57 GMT


 Hi

I am new to Android and creating my first application.

I want to create a file in the current directory. Basically I have a
file bundled with aplication package as raw resource. I want to make a
copy of this file in the current

file. The reason to create copy in current directory is that I want my
file reading code in native java, portable code.

To write a file in current directory I am doing following:

        String currentdir = System.getProperty("user.dir");
        String destination = currentdir + "test.txt";
        File fileCon = new File(destination);
        if( ! fileCon.exists() ){
                fileCon.createNewFile();
            }

But on createNewFile statement it is throwing IOException with
following message

java.io.IOException: Parent directory of file is not writable:
temp.txt

So my query is how can I create a file on current directory? The
location current directory is important here as I do not want to make
use of device specific hardcoded path or any Android API while reading
the file. This is so I want my file reading code portable.

Thanks

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


How to create a file in current directory?

by Dianne Hackborn » Thu, 30 Apr 2009 02:56:34 GMT


 You don't.  Use Context to create files and get the paths to your app's
directories.






-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~



How to create a file in current directory?

by prajapatmanoj » Thu, 30 Apr 2009 12:49:45 GMT


 Hi

I am new to Android and creating my first application.

I want to create a file in the current directory. Basically I have a
file bundled with aplication package as raw resource. I want to make a
copy of this file in the current file. The reason to create copy in
current directory is that I want my file reading code in native java,
portable code.

To write a file in current directory I am doing following:

        String currentdir = System.getProperty("user.dir");
        String destination = currentdir + "test.txt";
        File fileCon = new File(destination);
        if( ! fileCon.exists() ){
                fileCon.createNewFile();
            }

But on createNewFile statement it is throwing IOException with
following message

java.io.IOException: Parent directory of file is not writable:
temp.txt

So my query is how can I create a file on current directory? The
location current directory is important here as I do not want to make
use of device specific hardcoded path or any Android API while reading
the file. This is so because I want my file reading code portable.

Thanks
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. getBestLocationProvider.

I'm trying to use the getBestProvider to get a LocationProvider, but no
matter if I allow cost or not it returns null.  Here's the code I'm using.

Criteria criteria = new Criteria();
criteria.setCostAllowed(mUseAGPS);
mGPS = mLocationManager.getBestProvider(criteria);

Am I doing something wrong here?

--~--~---------~--~----~------------~-------~--~----~

2. ADT Installation Error: "requires plug-in org.eclipse.wst.sse.ui"

It seems that I should :

the checkboxes for both the ADT site, and the Callisto/Europa/Ganymede
Discovery Site (you may want to check Automatically select mirrors at
the bottom).
# Click Finish.


MY QUESTION :
HOW DO I HAD A NEW SITE "Callisto/Europa/Ganymede" ?
WHITHOUT A VALID URL I GET A IllegalArgument exception http Null

--~--~---------~--~----~------------~-------~--~----~

3. android root file system

4. hi,i am an android junior,

5. custom component

6. how to add lucene's jar file to eclipse classpath??

7. is there any way to run java file on the emulator??