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. How to make GLSurfaceView show smoothly

Hi Guys,

I've been block by this question for about a week. I tried to
implement a simple application: show a image, when user touch on
screen, I want to create a GLSurfaceView to cover the previous image.
Then show some 3D effects on this GLSurfaceView.

The logic is quite simple. But I have a serious problem. When
GLSurfaceView comes out, the whole screen become black, after 1-2
seconds, the GLSurfaceView with texture shows up. Is there any way to
make this smoothly? The 1-2 second black screen is really a bad user
experience.

Thanks a lot. Any idea/suggestion is appreciated.

-- 
Best Regards,
TANG Jiyu
Blog: http://jiyu.wordpress.com.cn/
ezkeypad: http://ezkeypad.tool100.com/

-- 

2. What version of Android to use when programming basic apps?

I also had seen that pie chart and information, and loved it.  Unfortunately, 
I notice that it's data from the turn of the year (week ending 4-Jan-2010).  
Does anyone know if Market folks generate this data more regularly, and if 
there's any web site we could look at to see it?

  I'd love to know what people are using this month, rather than 4+ months ago.

                             - Chris




-- 

3. Problem Observed with gestureoverlay method

4. Available data from an InputStream from URLConnection?

5. How to enable klogd / syslogd for debuggin

6. iPhone 4.0

7. How WebView render the webpage