andbook!.pdf - Learning Android Get an anddev.org - Android-Shirt Back to index
anddev.org Header Logo
FAQ Search Top rated articles Browse Feeds anddev.org - Authors Contact Details Register Log in

Working with Files

Goto page Previous  1, 2, 3, 4, 5  Next
 
       anddev.org - Android Development Community | Android Tutorials | Index -> Novice Tutorials
Author Message
tim
Freshman
Freshman


Joined: 03 Jul 2008
Posts: 7

PostPosted: Wed Sep 03, 2008 1:30 pm    Post subject: Reply with quote

...same problem here Confused
Back to top
View user's profile Send private message
haden
Experienced Developer
Experienced Developer


Joined: 11 Sep 2008
Posts: 74

PostPosted: Wed Oct 22, 2008 9:49 am    Post subject: Reply with quote

Nice tutorial plusminus.. Was really helpful in many ways..
Back to top
View user's profile Send private message Visit poster's website
rakesh_mehta
Experienced Developer
Experienced Developer


Joined: 14 Oct 2008
Posts: 73
Location: Ahmedabad(India)

PostPosted: Wed Oct 22, 2008 9:56 am    Post subject: Reply with quote

Nice Tutorials plus minus..

Thanks man.... Smile

_________________
Rakesh
Back to top
View user's profile Send private message Send e-mail
dinoguan
Freshman
Freshman


Joined: 11 Nov 2008
Posts: 4

PostPosted: Tue Nov 11, 2008 6:26 am    Post subject: File Writing Performance Reply with quote

Just wondering what kind of file writing performance you guys are experiencing.

I am just writing a list of floats in a short string to a file on the SD card. Interestingly I am getting the exact same performance in the emulator as when I test on the actual device!

Anyway it is taking about 4.7 seconds to write 57 entries of something like this
"[0.166][0.00][-0.02][0.00]"

so 26bytes * 57 entries = 1482bytes in 4.7 seconds = 315 bytes per second.

I am using the standard java FileWriter to write to the sd card.
The only things I can think of is that I am writing from a view, not from an activity, so perhaps there is some overhead or permissions difference?
And I am just doing it in a loop all at once.

Thanks, Andrew
Back to top
View user's profile Send private message
androooooid
Junior Developer
Junior Developer


Joined: 26 Sep 2008
Posts: 17

PostPosted: Wed Nov 19, 2008 9:38 am    Post subject: Reply with quote

Is it possible to see the file though file explorer Question
The code seems to work but I can't see where the file is through DDMS or File Explorer.
Back to top
View user's profile Send private message
dinoguan
Freshman
Freshman


Joined: 11 Nov 2008
Posts: 4

PostPosted: Fri Nov 28, 2008 9:42 pm    Post subject: Re: File Writing Performance Reply with quote

Well I figured out what my problem was. And it was much more general than just writing to a file. As I took my file.write call out of my loop, and just appended everything to one big string then dumped it to the file all at once. And it was still taking just as long to write!
Long story short, it was String.format(). Which has horrible performance! It was taking about a whole second to format 40 floats to %.2f. I was using this elsewhere also and it was significantly hurting my framerate.

Anyway, I now just have to do w/o string.format unless it is a one time call.

So my filewriter now writes 200 entries in a little over a second, much much better.

dinoguan wrote:
Just wondering what kind of file writing performance you guys are experiencing.

I am just writing a list of floats in a short string to a file on the SD card. Interestingly I am getting the exact same performance in the emulator as when I test on the actual device!

Anyway it is taking about 4.7 seconds to write 57 entries of something like this
"[0.166][0.00][-0.02][0.00]"

so 26bytes * 57 entries = 1482bytes in 4.7 seconds = 315 bytes per second.

I am using the standard java FileWriter to write to the sd card.
The only things I can think of is that I am writing from a view, not from an activity, so perhaps there is some overhead or permissions difference?
And I am just doing it in a loop all at once.

Thanks, Andrew
Back to top
View user's profile Send private message
Virtue
Freshman
Freshman


Joined: 28 Nov 2008
Posts: 2

PostPosted: Tue Dec 02, 2008 9:16 am    Post subject: How to write XML file? Reply with quote

Hello plusminus,
I wrote .txt file ok, now I want to write .xml file as follows :

<?xml version="1.0"?>
<result> YES </result>


Otherwise, replace YES = NO.
But I see problem with result tag, I have to use what method in source code java??

Thanks in advance,
Virtue.
Back to top
View user's profile Send private message
Anium
Freshman
Freshman


Joined: 06 Jan 2009
Posts: 3
Location: France

PostPosted: Sat Jan 24, 2009 1:57 pm    Post subject: Reply with quote

Hi,

I need to create files in a directory (/data/data/package/files/directory/new_file).

I can't use ctxt.openFileOutput(path_file, Context.MODE_WORLD_READABLE), an exception is thrown :
Quote:
01-24 12:29:33.496: ERROR/AndroidRuntime(14845): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.remotecontrol/org.remotecontrol.RemoteControl}: java.lang.IllegalArgumentException: File conf/menu.conf contains a path separator


I can get the file with ctxt.getFileStreamPath(path_file); but what can I do with this ?

Thx.
Back to top
View user's profile Send private message
nuggetgtr
Freshman
Freshman


Joined: 06 Jan 2009
Posts: 5

PostPosted: Wed Feb 04, 2009 2:58 am    Post subject: Reply with quote

Umm just need a little help, I want to store a couple of variables for an application not enough to need or use a database Im just wondering what the best way to format this in a text file would be?

I was going to write each stored value line by line, and read it out the same way but i cant seam to write it line by line, it seams to append to the end of the existing line.

using the bellow code
Java:
public void onClick(View view) {
               String sov = new String(spenton.getText().toString());
          
     try {
          OutputStreamWriter out = new OutputStreamWriter(openFileOutput("spenton1.txt",MODE_APPEND));

          out.write(sov +"\n");
          out.close();
     }


be great if someone can point me in the right direction on the best way to store info in a file and if thats line by line how do i go about writting it line by line?

Cheers for any help
Back to top
View user's profile Send private message
citrak
Once Poster
Once Poster


Joined: 29 Jan 2008
Posts: 1
Location: India

PostPosted: Wed Feb 04, 2009 10:18 am    Post subject: Reply with quote

Hi,

Try the following code snippet for opening a file which can be placed in any folder on your Emulator/device
This works with path separators also Smile

Java:

FileOutputStream fOut=null;
fOut= new FileOutputStream("/data/imsc/cfg/wrapper.cfg");
OutputStreamWriter osw = null;
osw = new OutputStreamWriter(fOut);
osw.write(data);


Also please make sure that you have the permissions to write in that particular folder.
You can change the permissions by giving a command like this from adb shell

# chmod 777 /data/imsc/cfg

- Kartic
Back to top
View user's profile Send private message
songotho
Developer
Developer


Joined: 03 Mar 2009
Posts: 35

PostPosted: Thu Mar 12, 2009 6:09 am    Post subject: Reply with quote

Hi,
Thank plusminus about the Tutorials. Would you show me the way to get data from xml in sdcard?
Actually, I have read a lot of tutorials so dont have anyone show it.

Thanks.
--Alex
Back to top
View user's profile Send private message
chetandl
Junior Developer
Junior Developer


Joined: 17 Mar 2009
Posts: 16

PostPosted: Thu Mar 19, 2009 7:31 am    Post subject: Image location for saving Reply with quote

Code:
@Override
   public void onPictureTaken(byte[] data, Camera camera) {
      try {
                  
         Bitmap image = BitmapFactory.decodeByteArray(data, 0, data.length);
         
         FileOutputStream stream = openFileOutput("example77"+ ".png", MODE_PRIVATE);
         OutputStreamWriter osw = new OutputStreamWriter(stream);
         image.compress(CompressFormat.PNG, 100, stream);         
         stream.flush();
         stream.close();
         
         
         Log.v(getClass().getSimpleName(), "onPictureTaken=" + data + " length = " + data.length);
      
      /*   filoutputStream.write(data);
         filoutputStream.flush();
         filoutputStream.close();*/
      } catch(Exception ex) {
         ex.printStackTrace();
      }
   }   


I am trying to save an image but it saves the image in sdcard still Sad
what may be the problem.
I want to store it in files folder of my application.
And one more thing how can I access this images for using it on ListActivity(for displaying it as images for each entry)
Back to top
View user's profile Send private message
Timmeah
Junior Developer
Junior Developer


Joined: 10 Feb 2009
Posts: 14

PostPosted: Sat Mar 21, 2009 10:12 pm    Post subject: Reply with quote

Does anyone how to write to a *.txt- (or XML-) file which is on a webserver?

So ftp with credentials, or just http with the chmodfile-rights at 777..
Back to top
View user's profile Send private message
marcelloma
Junior Developer
Junior Developer


Joined: 18 Mar 2009
Posts: 12

PostPosted: Thu Mar 26, 2009 3:47 pm    Post subject: Reply with quote

is there anyway to automatically scan all the objects in the drawable folder and put their ids into an array?
Back to top
View user's profile Send private message
andreleitao
Experienced Developer
Experienced Developer


Joined: 10 Mar 2009
Posts: 55
Location: Recife - Brazil

PostPosted: Wed Apr 01, 2009 9:24 pm    Post subject: Reply with quote

Thanks for the tutorial plusminus!!! Very Happy It's amazing. Buuuuttttt... I would like to know where the written file is placed. It's not become 'visible' to the programmer, right? I mean the written file is does not appear on Eclipse Package Explorer. I'm right?

Thanks Smile
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
       anddev.org - Android Development Community | Android Tutorials | Index -> Novice Tutorials All times are GMT + 1 Hour
Goto page Previous  1, 2, 3, 4, 5  Next
Page 4 of 5

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


© 2007, Android Development Community
All rights reserved.
Powered by phpBB.