Monday, July 26, 2010

[android-developers] Re: trying to save to internal memory; length of content always returns 0

You didn't flush/close fred.

On Jul 24, 2:13 pm, bvh <atres...@gmail.com> wrote:
> Heya,
>
> I'm trying to write something to the internal memory, but whenever I
> try to check if it has written the right information, it returns
> length 0.
>
> The following code is triggered by a buttonpress, which is suppose to
> store the information the user has written in a textform. 'Displaybox'
> is a TextView which contains the user's addition.
>
> String FILENAME = "geonag.txt";
>                                 String stringtowrite = Displaybox.getText().toString();
>                 Log.i("reached", "convert" + stringtowrite);
>                                 FileOutputStream fos;
>                                 try {
>                                         fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE);
>
>                                         OutputStreamWriter fred = new OutputStreamWriter(fos);
>
>                                         fred.write(stringtowrite.toCharArray(), 0,
> stringtowrite.length());
>                                         fos.flush();
>                                         fos.close();
>
>                 Log.i("reached", "running text 1");
>                                 } catch (FileNotFoundException e) {
>                                         // TODO Auto-generated catch block
>                                         e.printStackTrace();
>                                 } catch (IOException e) {
>                                         // TODO Auto-generated catch block
>                                         e.printStackTrace();
>                                 }
>
>                 Log.i("reached", "after file creation");
>
>                 // read this
>
>                                 FileInputStream fis2;
>                                 try {
>                                         fis2 = openFileInput(FILENAME);
>
>                                         InputStreamReader isr = new InputStreamReader(fis2);
>
>                                         Log.i("reached","length" + fis2.available());
>                                         char[] inputBuffer = new char[fis2.available()];
>                                         isr.read(inputBuffer);
>
>                                 String Retrievetext = new String(inputBuffer);
>                                 Log.i("reached", "extra"+ Retrievetext);
>                                 Displaybox.setText(Retrievetext);
>
>                                 fis2.close();
>                                 Log.i("reached", "running text 2");
>
>                                 } catch (FileNotFoundException e1) {
>                                         Log.i("reached", "file not found");
>                                         // TODO Auto-generated catch block
>                                         e1.printStackTrace();
>
>                                 } catch (IOException e) {
>
>                                         Log.i("reached", "ioexception");
>                                         // TODO Auto-generated catch block
>                                         e.printStackTrace();
>
>                                 }
>
> Log.i("reached","length" + fis2.available()); --- this always seems to
> return length 0.
> Is there any way of checking whether the file is being created at all?
> That would already help a lot.
>
> Cheers,

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment