Masalah:
Apabila menulis fail kurang daripada 2kb, ia secara langsung melaporkan masalah ruang yang tidak mencukupi Fail yang diminta oleh retrofit2 boleh digunakan untuk mengetahui sebabnya
D/OkHttp: --> DAPATKAN http://musicdata.baidu.com/da... http/1.1
D/OkHttp: <-- 200 OK http://musicdata. baidu .com/da... (98ms, isi 1877-bait)
D/ContentValues: onResponse: Permintaan fail lirik berjaya
I/art: Thread[2,tid=3036,WaitingInMainSignalCatcherLoop,Thread*=0xae402000,Thread*=0xae402000, , "Signal Catcher"]: bertindak balas kepada isyarat 3
I/art: Menulis surih tindanan ke '/data/anr/traces.txt'
W/System.err: java.io.IOException: tulis gagal: ENOSPC (Tiada ruang ditinggalkan pada peranti)
W/System.err: di libcore.io.IoBridge.write(IoBridge.java:498)
W/System.err: di java.io.FileOutputStream.write(FileOutputStream.java:186)
W / System.err: di com.wang.mymusic.data.MusicData.lrcFile(MusicData.java:163)
W/System.err: at com.wang.mymusic.data.MusicData.access$200(MusicData.java:40 )
W/System.err: di com.wang.mymusic.data.MusicData$3.onResponse(MusicData.java:123)
W/System.err: at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCallAllAdaptorCallbackCall($1$1. 68 )
W/System.err: di android.os.Handler.handleCallback(Handler.java:739)
W/System.err: di android.os.Handler.dispatchMessage(Handler.java:95)
W/System . err: di android.os.Looper.loop(Looper.java:148)
W/System.err: di android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err: at java. lang .reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err: at com.android . internal.os.ZygoteInit.main(ZygoteInit.java:616)
W/System.err: Disebabkan oleh: android.system.ErrnoException: gagal menulis: ENOSPC (Tiada ruang yang tinggal pada peranti)
W/System.err: di libcore .io.Posix.writeBytes(Kaedah Asli)
W/System.err: di libcore.io.Posix.write(Posix.java:271)
W/System.err: di libcore.io.BlockGuardOs.write(BlockGuardOs . java:313)
W/System.err: di libcore.io.IoBridge.write(IoBridge.java:493)
W/System.err: ... 12 lagi
I/art: Latar belakang separa tanda serentak sapu GC membebaskan 83995(3MB) objek AllocSpace, 0(0B) objek LOS, 12% percuma, 27MB/31MB, dijeda 3.141ms jumlah 131.690ms
I/seni: Latar belakang melekit tanda serentak objek GC dibebaskan 104777(4ceMB) AllocSpace(4ceMB) AllocSpace(4ceMB) 0B) ) Objek LOS, 0% percuma, 34MB/34MB, dijeda 5.311ms jumlah 163.136ms
// Simpan fail lirik ke cakera
private File lrcFile(Context context,ResponseBody respon,String title,String author) throws IOException {
//create a file
File filedirectory;
File file;
String name=title+"_"+author+".lrc";
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable()){
filedirectory=new File(context.getExternalCacheDir()+File.separator+"lrc");
file=new File(filedirectory+File.separator+name);
}else {
filedirectory=new File(context.getCacheDir()+File.separator+"lrc");
file=new File(filedirectory+File.separator+name);
}
if (!filedirectory.exists()){
filedirectory.mkdir();
}
if(!file.exists()){
file.createNewFile();
}
InputStream in=respon.byteStream();
try {
OutputStream out=new FileOutputStream(file);
byte[] b=new byte[2048];
int fileread=in.read(b);
while (fileread!= -1){
out.write(b,0,fileread);
}
out.flush();
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
sambil (fail dibaca!= -1){
Adalah salah menggunakan gelung ini harus ditukar kepada jika
.