android regarding file read from sandbox -


My name is a file named settings.xml that I copy from property to sandbox, if file does not exist in the sandbox is . This file, then, I am trying to read from sandbox in another activity. I'm getting errors, please help me Copy file from the sync box if not available in the sandbox / private zero copymyfiles (string filename) {FileInputStream fInp; Try {fInp = openFileInput (file name); If (fInp! = Null) {log.i (â "???", "Setting file is found in the sandbox setting");}} Catch (FileNote ExpressE 1) {/ * file is not in the sandbox . Property * / e1.printStackTrace () from; AssetManager assetManager = this.getAssets (); {InputStream = assetManager.open (filename); Log.i (a "", "opening settings xml"); {FileOutputStream FOut = openFileOutput (file name, MODE_WORLD_READABLE); OutputStream Water Out = New OutputStream Witter (Out); {Try current four; String result = ""; While (in.available ()> gt; {current = (char) in.read (); Results = result + String.valueOf (current); } Logs. V ("apr 4", result); Out.write (results); } Hold (IOException pre) {ex.printStackTrace (); } Finally {try {if (in! = Null) in.close (); If (outside! = Zero) out Close (); } Hold (IOException pre) {ex.printStackTrace (); }}} Hold (FileNotFoundException E) {// TODO Automatic Generating Holding Block e.printStackTrace (); Log.i ("test", "Error opening settings from sandbox");}} Catch (IOE EXPRESS E) {// Auto-Generated Catch Block e.printStackTrace (); Log.i (â ???? "," Error getting Asset Manager ");}}

After this I am trying to read the file in new activity

  FileInputStream fIn = null; file file = getBaseContext (). GetFileStreamPath ("Settings.xml"); if (file.exists ()) {Log.v ("", "file exists in the sandbox Try to read {log "V" ("", "attempt to read from sandbox"); fIn = openFileInput ("Settings.xml");} hold (FileNotFoundException e2) {// TODO Auto-Generated Calls Block Log.v ("", "failed to read from sandbox?"); E2.printStackTrace ();}   

But it gives me the "java.lang.NullPointerException" error

To resolve this problem Try adding it:

  context = getActivity (); FileInputStream wings = context.openFileInput (FILENAME);   

It should work.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -