今天碰到一個問題,後臺給我一個json字符串,由於太長,logcat打不全,上網查了資料,好像是logcat有長度限制,需要分段打印。
後來我就想,直接新建一個txt,把這個string放進去,再用ADM導出文件就好了。
代碼
//獲取SD卡的路徑
String pathString = Environment.getExternalStorageDirectory().getPath();
File file = new File(pathString+"/"+"xxx.txt");
//判斷文件是否存在
if(!file.exists()){
//創建新文件
file.createNewFile();
}
//創建一個文件輸出流
FileOutputStream out = new FileOutputStream(file,true);//true表示在文件末尾添加
out.write(s.getBytes("UTF-8"));
out.close();