/**文件保存到本地*/
public static void saveFile(Context context ,String data) {
try {
FileOutputStream fos=context.openFileOutput("json", Context.MODE_PRIVATE);
fos.write(data.getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**本地文件读取*/
public static String readFile(Context context ,String fileName) {
try {
FileInputStream inStream=context.openFileInput(fileName);
ByteArrayOutputStream stream=new ByteArrayOutputStream();
byte[] buffer=new byte[1024];
int length=-1;
while((length=inStream.read(buffer))!=-1) {
stream.write(buffer,0,length);
}
stream.close();
inStream.close();
return stream.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
文件的保存及读取
最新推荐文章于 2022-03-20 15:01:03 发布