android 创建图片文件
private File mFile;
public void createF() {
new Thread(new Runnable() {
@Override
public void run() {
mFile = new File(Environment.getExternalStorageDirectory() + "/AAAF/" + "AAA.png");
if (mFile.exists()) {
mFile.delete();
}
try {
mFile.getParentFile().mkdirs();
//创建文件
mFile.createNewFile();
FileOutputStream outputStream = new FileOutputStream(mFile);
InputStream in = getAssets().open("yu.png");
int read = in.read();
while (read != -1) {
outputStream.write(read);
read = in.read();
}
outputStream.flush();
outputStream.close();
//给一个吐司提示,显示创建成功
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "文件创建成功", Toast.LENGTH_SHORT).show();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
yu.png