我有一个问题,试图让我的android手机.png图像。 我现在这个地步:如何获取.png到Android手机(external_sd)
URL url = new URL ("http://oranjelan.nl/oranjelan-bg.png");
InputStream input = url.openStream();
try {
String storagePath = Environment.getExternalStorageDirectory();
OutputStream output = new FileOutputStream (storagePath + "/oranjelangbg.png");
try {
byte[] buffer = new byte[1000000];
int bytesRead = 0;
while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
output.write(buffer, 0, bytesRead);
}
} finally {
output.close();
}
} finally {
input.close();
}
但我得到以下错误:STRING storagePath = Environment.getExternalStorageDirectory();压缩机说不能将文件转换为字符串。
然后,如果我愚弄了一下,试试这段代码:
URL url;
void setup() {
try {
URL url = new URL ("http://oranjelan.nl/oranjelan-bg.png");
InputStream input = url.openStream();{
try {
String storagePath = Environment.getExternalStorageDirectory().getName();
OutputStream output = new FileOutputStream (storagePath + "/oranjelangbg.png");
try {
byte[] buffer = new byte[1000000];
int bytesRead = 0;
while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
output.write(buffer, 0, bytesRead);
}
} finally {
output.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
throw new RuntimeException(e);
} finally {
try {
input.close();
} catch (IOException e) {
// TODO Auto-generated catch block
throw new RuntimeException(e);
}
}
}
} catch (MalformedURLException ex) {
throw new RuntimeException(ex);
} catch (IOException e) {
// TODO Auto-generated catch block
throw new RuntimeException(e);
}
}
}
那么我的Android冻结当我启动应用程序。
有没有人有任何想法?
很多很多谢谢你的回复,我现在必须退出,并且会在星期一回来,然后回复并查看此信息。 – 2012-07-06 15:31:32
尝试下载不同线程中的图像。它会克服冻结问题.. – AAnkit 2012-07-06 15:36:10
非常感谢你们,我想我现在就能得到它,所有的芒果都很好!并帮助我很多! – 2012-07-09 07:48:06