我正在尝试从URL读取文件并写入我的SD卡。因为它与.js .css和.txt文件等其他文件一起工作良好......但它不能与.png .jpg .bmp和.gif一起使用。我的代码是
String path = dir + value;
File localConfigfile = new File(
Environment.getExternalStorageDirectory()
+ "/Avalon/assets/www/" + path);
String responseString = RequestMgr.GetWebSource(DomainName
+ "/" + Heirarchy + "/" + Serverpath);
FileOutputStream out;
if (localConfigfile.exists()) {
localConfigfile.delete();
out = new FileOutputStream(localConfigfile);
out.write(responseString.getBytes());
}
}
请在这里帮助我,我很震惊
答案 0 :(得分:1)
尝试使用位图读取文件。如果您使用位图和URI读取性能
,那将是一个不错的选择答案 1 :(得分:1)
private void storeImage(Bitmap image) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null) {
Log.d(TAG,
"Error creating media file, check storage permissions: ");// e.getMessage());
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
image.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
} }