Back to project page UTHPortal-Android-Gradle.
The source code is released under:
MIT License
If you think the Android project UTHPortal-Android-Gradle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.uth.uthportal.buffers; //from www . j a va 2 s. c o m import java.io.FileInputStream; import java.io.FileOutputStream; import android.content.Context; import android.util.Log; /** * File operations, focused primarily on saving and loading * files from private storage. Used to Store information * locally so it's available off-line. * @author GeorgeT * */ public class FileOperation { String path; Context context; public FileOperation(String _path, Context _context){ path = _path; context = _context; } public String LoadFromPrivate(){ FileInputStream fis; String result = new String(); try { fis = context.openFileInput(path); //create a new byte array with available byte from the stream as size byte input[] = new byte[fis.available()]; while(fis.read(input) != -1){}; //if not eof, read more result += new String(input); //create string from bytes } catch (Exception e) { result = null; Log.d("Error:", e.getMessage()); } return result; } public Boolean SaveToPrivate(String buffer){ FileOutputStream outputStream; try { outputStream = context.openFileOutput(path, Context.MODE_PRIVATE); outputStream.write(buffer.getBytes()); outputStream.close(); return true; } catch (Exception e) { Log.d("Error:", e.getMessage()); return false; } } }