Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.Context;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.math.BigDecimal;
- import java.math.BigInteger;
- public class Saver {
- static FileOutputStream fos;
- static FileInputStream fis;
- public static void save(String filename, String data, Context c){
- try {
- fos = c.openFileOutput(filename, Context.MODE_PRIVATE);
- fos.write(data.getBytes());
- fos.close();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- String file;
- public String getFile(){return file;}
- public void setFile(String loc){
- file = loc;
- }
- String result;
- private static String mainLoad(String fn, Context c){
- String collected = null;
- try{
- fis = c.openFileInput(fn);
- byte[] dataArray = new byte[fis.available()];
- while(fis.read(dataArray) != -1){
- collected = new String(dataArray);
- }
- }catch(Exception e){
- e.printStackTrace();
- return null;
- }finally{
- try {
- fis.close();
- return collected;
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
- }
- public static int loadInt(String fn, Context c){
- if(mainLoad(fn,c) == null) return 0;
- else return Integer.parseInt(mainLoad(fn,c));
- }
- public static double loadDouble(String fn, Context c){
- if(mainLoad(fn,c) == null) return 0;
- else return Double.parseDouble(mainLoad(fn,c));
- }
- public static float loadFloat(String fn, Context c){
- return Float.parseFloat(mainLoad(fn,c));
- }
- public static String loadString(String fn, Context c){
- return mainLoad(fn, c);
- }
- public static Boolean loadBoolean(String fn, Context c){
- if(mainLoad(fn,c) == null) return false;
- else return Boolean.parseBoolean(mainLoad(fn,c));
- }
- public static BigInteger loadBigInteger(String fn, Context c){
- return new BigInteger(mainLoad(fn,c));
- }
- public static BigDecimal loadBigDecimal(String fn, Context c){
- return new BigDecimal(mainLoad(fn,c));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment