Sie sind auf Seite 1von 1

package com.rycking.boomboxparty; import import import import import java.io.File; java.io.FileInputStream; java.io.FileNotFoundException; java.io.FileOutputStream; java.io.

IOException;

import android.content.Context; import android.util.Log; public class Preferencias { private static final String TAG = "ManageFile"; private Context context; public Preferencias(Context context){ this.context = context; } /** * Escreve no arquivo texto. * @param text Texto a ser escrito. * @return True se o texto foi escrito com sucesso. */ public boolean SalvarArq(String text, String arq){ try { // Abre o arquivo para escrita ou cria se no existir FileOutputStream out = context.openFileOutput(arq, Context.MODE_PRIVATE); out.write(text.getBytes()); out.write("\n".getBytes()); out.flush(); out.close(); return true; } catch (Exception e) { Log.e(TAG, e.toString()); return false; } } //ler fundo gravado public String LerArq(String arq) throws FileNotFoundException, IOException{ File file = context.getFilesDir(); File textfile = new File(file + "/"+arq); FileInputStream input = context.openFileInput(arq); byte[] buffer = new byte[(int)textfile.length()]; input.read(buffer); return new String(buffer); } }

Das könnte Ihnen auch gefallen