怎么使用FileOutputStream在指定位置写入文件
展开全部
* 拷贝文件,
* @param oldPath 旧文件路径
* @param newPath 新文件路径
* @throws Exception
*/
private void copyFile(String oldPath, String newPath) throws Exception{
int bytesum = 0;
int byteread = 0;
File oldFile = new File(oldPath);
InputStream in = null;
OutputStream out = null;
if(oldFile.exists()){
try {
in = new FileInputStream(oldPath);
out = new FileOutputStream(newPath);
byte[] buffer = new byte[1024*5];
while((byteread = in.read(buffer)) != -1){
bytesum += byteread;
System.out.println(bytesum);
out.write(buffer, 0, byteread);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new Exception("输入myeclipse的路径不正确");
}finally{
if(in != null)
in.close();
if(out != null)
out.close();
}
}
}
* @param oldPath 旧文件路径
* @param newPath 新文件路径
* @throws Exception
*/
private void copyFile(String oldPath, String newPath) throws Exception{
int bytesum = 0;
int byteread = 0;
File oldFile = new File(oldPath);
InputStream in = null;
OutputStream out = null;
if(oldFile.exists()){
try {
in = new FileInputStream(oldPath);
out = new FileOutputStream(newPath);
byte[] buffer = new byte[1024*5];
while((byteread = in.read(buffer)) != -1){
bytesum += byteread;
System.out.println(bytesum);
out.write(buffer, 0, byteread);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new Exception("输入myeclipse的路径不正确");
}finally{
if(in != null)
in.close();
if(out != null)
out.close();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询