1
我做了一個簡單的函數來從URL寫入文件。一切正常,直到好out.write(),我的意思是有沒有例外,但它只是不寫什麼到文件Android寫入文件
這裏的代碼
private boolean getText(String url, String name) throws IOException {
if(url!=null){
FileWriter fstream = new FileWriter(PATH+"/"+name+".txt");
BufferedWriter out = new BufferedWriter(fstream);
URL _url = new URL(url);
int code = ((HttpURLConnection) _url.openConnection()).getResponseCode();
if(code==200){
URLConnection urlConnection = _url.openConnection(); //
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
int bytesRead = 0;
byte[] buffer = new byte[1024];
while ((bytesRead = in.read(buffer)) != -1) {
String chunk = new String(buffer, 0, bytesRead);
out.write(chunk);
}
return true;
}
out.close();
}
return false;
}
有人能告訴我什麼是錯的嗎?
是創建的文件? – Otra
是的,它的空 – krp
也是,所有的權限都設置好了,等等 - 我已經完成了寫圖片和思想文本將會更容易,但即時得到真正的沮喪 – krp