Working with Files

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby tim » Wed Sep 03, 2008 1:30 pm

...same problem here :?
User avatar
tim
Freshman
Freshman
 
Posts: 7
Joined: Thu Jul 03, 2008 3:05 pm

Top

Postby haden » Wed Oct 22, 2008 9:49 am

Nice tutorial plusminus.. Was really helpful in many ways..
haden
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Thu Sep 11, 2008 11:51 am

Postby rakesh_mehta » Wed Oct 22, 2008 9:56 am

Nice Tutorials plus minus..

Thanks man.... :)
Rakesh
User avatar
rakesh_mehta
Experienced Developer
Experienced Developer
 
Posts: 73
Joined: Tue Oct 14, 2008 6:46 am
Location: Ahmedabad(India)

File Writing Performance

Postby dinoguan » Tue Nov 11, 2008 6:26 am

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
dinoguan
Freshman
Freshman
 
Posts: 4
Joined: Tue Nov 11, 2008 6:01 am

Postby androooooid » Wed Nov 19, 2008 9:38 am

Is it possible to see the file though file explorer :?:
The code seems to work but I can't see where the file is through DDMS or File Explorer.
androooooid
Junior Developer
Junior Developer
 
Posts: 17
Joined: Fri Sep 26, 2008 8:47 pm

Re: File Writing Performance

Postby dinoguan » Fri Nov 28, 2008 9:42 pm

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
dinoguan
Freshman
Freshman
 
Posts: 4
Joined: Tue Nov 11, 2008 6:01 am

Top

How to write XML file?

Postby Virtue » Tue Dec 02, 2008 9:16 am

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.
Virtue
Freshman
Freshman
 
Posts: 2
Joined: Fri Nov 28, 2008 9:33 am

Postby Anium » Sat Jan 24, 2009 1:57 pm

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 :
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.
Anium
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 06, 2009 10:36 am
Location: France

Postby nuggetgtr » Wed Feb 04, 2009 2:58 am

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
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onClick(View view) {
  2.  
  3.                         String sov = new String(spenton.getText().toString());
  4.  
  5.                
  6.  
  7.         try {
  8.  
  9.                 OutputStreamWriter out = new OutputStreamWriter(openFileOutput("spenton1.txt",MODE_APPEND));
  10.  
  11.  
  12.  
  13.                 out.write(sov +"\n");
  14.  
  15.                 out.close();
  16.  
  17.         }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


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
nuggetgtr
Freshman
Freshman
 
Posts: 5
Joined: Tue Jan 06, 2009 3:14 am

Postby citrak » Wed Feb 04, 2009 10:18 am

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 :-)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. FileOutputStream fOut=null;
  3.  
  4. fOut= new FileOutputStream("/data/imsc/cfg/wrapper.cfg");
  5.  
  6. OutputStreamWriter osw = null;
  7.  
  8. osw = new OutputStreamWriter(fOut);
  9.  
  10. osw.write(data);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


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
citrak
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Jan 29, 2008 6:51 am
Location: India

Postby songotho » Thu Mar 12, 2009 6:09 am

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
songotho
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Tue Mar 03, 2009 1:59 am

Image location for saving

Postby chetandl » Thu Mar 19, 2009 7:31 am

Code: Select all
@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 :(
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)
chetandl
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue Mar 17, 2009 9:17 am

Postby Timmeah » Sat Mar 21, 2009 10:12 pm

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..
Timmeah
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Feb 10, 2009 4:30 pm

Postby marcelloma » Thu Mar 26, 2009 3:47 pm

is there anyway to automatically scan all the objects in the drawable folder and put their ids into an array?
marcelloma
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Mar 18, 2009 4:31 pm

Postby andreleitao » Wed Apr 01, 2009 9:24 pm

Thanks for the tutorial plusminus!!! :D 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 :)
andreleitao
Experienced Developer
Experienced Developer
 
Posts: 70
Joined: Tue Mar 10, 2009 9:56 pm
Location: Recife - Brazil

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: Google Feedfetcher and 3 guests