提交 1249e955 编写于 作者: 只猪会上树's avatar 只猪会上树

上传新文件

上级 ec56c0a9
package example.com.save;
/**
* 内部文件文件读写
*/
import android.content.Context;
import android.icu.util.Calendar;
import android.os.Build;
import android.support.annotation.RequiresApi;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.nio.ByteBuffer;
public class FileProcess {
//写入文件
public static boolean writeInternalData(Context context, String strPath, int intTxt) {
FileOutputStream fos;
try{
fos=context.openFileOutput(strPath,0);
try{
String strTxt=Integer.toString(intTxt);
fos.write(strTxt.getBytes());
return true;
}catch (IOException e){
e.printStackTrace();
return false;
}
}catch (FileNotFoundException e){
e.printStackTrace();
return false;
}
}
//读取文件
public static int readInternalData(Context context, String strPath){
FileInputStream fis ;
byte[] buffer;
try{
fis=context.openFileInput(strPath);
try{
buffer=new byte[fis.available()];
fis.read(buffer);
String file_str=new String(buffer);
int number=Integer.valueOf(file_str);
return number;
}catch (IOException e){
e.printStackTrace();
return 0;
}
}catch (FileNotFoundException e){
e.printStackTrace();
return 0;
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册