像标题状态我只是试图下载test.txt文件,下面的URL并保存在内部,理想情况下在可绘制内。Android,下载一个.txt文件,并保存在内部
我一直在试图修改这个工作,但会收效甚微我不断收到“无法下载空”的错误
int count;
try {
URL url = new URL("https://www.darkliteempire.gaming.multiplay.co.uk/testdownload.txt");
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
InputStream is = url.openStream();
File testDirectory = new File(Environment.getExternalStorageDirectory() + "/Download");
if (!testDirectory.exists()) {
testDirectory.mkdir();
}
FileOutputStream fos = new FileOutputStream(testDirectory + "/test.txt");
byte data[] = new byte[1024];
long total = 0;
int progress = 0;
while ((count = is.read(data)) != -1) {
total += count;
int progress_temp = (int) total * 100/lenghtOfFile;
fos.write(data, 0, count);
}
is.close();
fos.close();
} catch (Exception e) {
Log.e("ERROR DOWNLOADING", "Unable to download" + e.getMessage());
}
必须有这样做一个简单的方法? 该文件本身是微小的,也许3或4行文本,所以我不需要任何花哨
您的网址错误“https://www.http://dark ...” – fredcrs
'https://www.http://'? – njzk2