Maybe change MODE_PRIVATE to MODE_WORLD_READABLE?

On Sunday, October 14, 2012 1:44:21 PM UTC-5, Rajiv Singh wrote:
>
> Hi there, 
> I am creating an app to find duplicate files .. i am using 
> ArrayList<File> to hold all File Objects. I am creating this arraylist 
> in a service and want to pass this arraylist to another Activity. For 
> this i am serializing the ArrayList to a file :- 
>
> public void serializeList()  { 
>         String fname = "filelist.bin"; 
>         //File dir = getDir("DFR", MODE_PRIVATE); 
>         try { 
>                  fos = openFileOutput(fname, MODE_PRIVATE); 
>                 obs = new ObjectOutputStream(fos); 
>                 obs.writeObject(sOnlyFiles); 
>                 obs.flush(); 
>                 obs.close(); 
>                 fos.close(); 
>         } catch (FileNotFoundException e) { 
>                 // TODO Auto-generated catch block 
>                 e.printStackTrace(); 
>         } catch (IOException e) { 
>                 // TODO Auto-generated catch block 
>                 e.printStackTrace(); 
>         } 
> } 
>
> i am able to fetch the file from app's private directory in the 
> onCreate() method of my ListActivity :- 
>
> protected void onCreate(Bundle savedInstanceState) { 
>
>                         stopService(new Intent(this, BgService.class)); 
>
>                 //        deserializeList(); 
>                        // i am fetching all the files from the app's 
> local directory and this is executing successfully 
>                         File file[] = getFilesDir().listFiles(); 
>
>                         for(int i=0;i<file.length;i++){ 
>                                 Toast.makeText(getApplicationContext(), 
> file[i].getName()+" 
> "+file[i].length(), 2000).show(); 
>                         } 
>                 //        stopService(new Intent(this, BgService.class)); 
>                         //setListAdapter(new OnlyFilesAdapter()); 
>                         //Bundle filelist = getIntent().getExtras(); 
>                         super.onCreate(savedInstanceState); 
>
>
>                 } 
>
> i am deserializing to get back the ArrayList and feeding that to 
> BaseAdapter for displaying the result in ListActivity:- 
> public void deserializeList(){ 
>         Object tolist =null; 
>         String filename = "filelist.bin"; 
>         //File dir = getDir("DFR", getApplicationContext().MODE_PRIVATE); 
>         try { 
>
>                 fis = openFileInput(filename);  /******************* here 
> i am 
> getting error***************/ 
>
>                 if(fis!=null){ 
>                         obs = new ObjectInputStream(fis); 
>                         tolist = obs.readObject(); 
>                         @SuppressWarnings("unchecked") 
>                         ArrayList<File> tolist2 = (ArrayList<File>)tolist; 
>                         ListoFiles = tolist2; 
>                         obs.close(); 
>                         fis.close(); 
>                         Toast.makeText(getApplicationContext(), 
> ListoFiles.size(), 
> 5000).show(); 
>                 }else 
>                         Toast.makeText(getApplicationContext(), "file not 
> available", 
> 2000).show(); 
>                 } catch (Exception e) { 
>
>         } 
>
> on deSerializing i am getting following error :- 
> java.lang.RuntimeException: Unable to start activity 
> ComponentInfo{my.com.filebrowser/my.com.filebrowser.AllFiles}: 
> android.content.res.Resources$NotFoundException: String resource ID 
> #0x7e5 
>
> please help me getting out of this ... 
>
> Thanks 
>
>

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

Reply via email to