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