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. Skype-an via Android

Halo,
Udah ada yg bisa skype-an via Android?
Kemaren saya nyoba pake app Fring, bisa dial ke skype temen, dan kedengeran 
suara dia. Tapi suara saya ga kedengeran di skype dia.


-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

-- 
"Indonesian Android Community [id-android]" 

2. Generating a static HashMap from resources?

In my app, I'd like to define some static resources in an xml file
which can be accessed via a HashMap. I know I can do this at run time
in a manner similar to the one which is described here:

3. How to create "unsynced" contacts and insert it in the system PhoneBook with Android 2.1?

4. How to make the calling activity wait for the sub-activity to return and then proceed

5. How to parse JSON in Java?

6. How to make the calling activity wait for the sub-activity to return and then proceed

7. update of android application