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. Images from Xml

Hi everyone! Can somebody help wih such problem.
I need to take out of XML file images to view it on display using XML
parser.
I proclaimed in xml file passes to images.

Using something like it:

res/xml/game.xml

<game>
<level>
<bg />
<items>
<item android:drawable="@drawable/item1" ... />
<item android:drawable="@drawable/item2" ... />
</items>
</level>
<level>
</level>

Is it clear??

So in java class I need to use XmlResourseParser

-- 

2. android.bluetooth.a2dp.intent.action.SINK_STATE_CHANGED

HI everybody,

im currently looking for the way that my app knows when the phone has
being paired and connected to a bluetooth headset device.

I read something about this intent, but not on the Reference
documentation of http://developer.android.com

android.bluetooth.a2dp.intent.action.SINK_STATE_CHANGED

is this actually working, is it officially supported.

I mean, can we just register a broadcastreceiver to handle this
intent , check for the EXTRA_STATE string extra to see if it equals
STATE_CONNECTED and be sure that the phone is now connected with a
bluetooth headset device ???

What about this BluetoothA2dpService class?? There is no official
documentation about this, everything i found i from code snippets of
the android OS source code.

What do you guys think about this?

Greetings,

Alex.

3. Need Calendar.apk and CalendarProvider.apk

4. Remote Test your apps on real phones with Sony Ericsson Perfecto Mobile

5. Deactivate any calls to Log methods before publishing app

6. Experience with different Android devices and apps shown in Android Market

7. how to get user info