public class MycopyTest {
public static void main(String[] args) {
File src = new File("D:/1.jpg");
// D:/1.jpg必须的存在不然会报错
File dest = new File("D:/2.jpg");
// 如果D:/2.jpg存在则覆盖,如果不存在则新建
streamCopy(src, dest);
}
private static void readCopy(File src,File dest)
{
FileReader fr=null;
FileWriter fw=null;
BufferedReader br=null;
BufferedWriter bw=null;
try {
fr=new FileReader(src);
fw=new FileWriter(dest);
br=new BufferedReader(fr);
bw=new BufferedWriter(fw);
String str;
while((str=br.readLine())!=null)
{
bw.write(str);
bw.newLine();
}
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
bw.close();
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void streamCopy(File src, File dest) {
FileInputStream fis = null;
FileOutputStream fos = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
fis = new FileInputStream(src);
fos = new FileOutputStream(dest);
bis = new BufferedInputStream(fis);
bos = new BufferedOutputStream(fos);
int len;
byte[] b = new byte[1024];
while ((len = bis.read(b)) != -1) {
bos.write(b, 0, len);
// bos.write(b,0,len);是把读到数组的大小字节写入
// bos.write(b);最后一次如果数组未写满的话就会多读。
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
bos.close();
bis.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class InputStreamWriterTest {
public static void main(String[] args) {
File src = new File("D:/Files/狗屁.txt");
File dest = new File("D:/Files/斯密斯.txt");
BufferedWriter bw = null;
BufferedReader br = null;
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(src);
fos = new FileOutputStream(dest);
InputStreamReader ir = new InputStreamReader(fis, "GBK");
OutputStreamWriter ow = new OutputStreamWriter(fos, "GBK");
bw = new BufferedWriter(ow);
br = new BufferedReader(ir);
String str;
while ((str = br.readLine()) != null) {
bw.write(str);
bw.newLine();
bw.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
bw.close();
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有