public boolean fileCopy(String from, String to) {
Log.i("upgrade_copy","from path "+from );
Log.i("upgrade_copy","to path "+to );
boolean result = false;
int size = 1 * 1024;
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream(from);
out = new FileOutputStream(to);
byte[] buffer = new byte[size];
int bytesRead = -1;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
out.flush();
result = true;
Log.i("upgrade_copy","copy sucess " );
File delFile = new File(from);
if (delFile.exists()){
delFile.delete();
Log.i("upgrade_copy","del from path file " );
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
}
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
}
}
return result;
}
java 复制文件的写法
猜你喜欢
转载自blog.csdn.net/u010689853/article/details/112917910
今日推荐
周排行