复制文本的五种方式:
1)
public static void main(String[] args) throws IOException{
FileReader fr=new FileReader("F:\\a.txt");
FileWriter fw=new FileWriter("D:\\f.txt");
char[] chs=new char[1024];
int len=0;
while((len=fr.read(chs))!=-1){
fw.write(chs,0,len);
fw.flush();
}
fr.close();
fw.close();
}
}
2)
public class CopyFileDemo4 {
public static void main(String[] args) throws IOException{
FileReader fr=new FileReader("F:\\a.txt");
FileWriter fw=new FileWriter("D:\\e.txt");
int by=0;
while((by=fr.read())!=-1){
fw.write(by);
fw.flush();
}
fr.close();
fw.close();
}
}
3)
public class CopyFileDemo9 {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new FileReader("F:\\a.txt"));
BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\j.txt"));
int by=0;
while((by=br.read())!=-1){
bw.write(by);
bw.flush();
}
br.close();
bw.close();
}
}
4)
public class CopyFileDemo10 {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new FileReader("F:\\a.txt"));
BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\k.txt"));
char[] chs=new char[1024];
int len=0;
while((len=br.read(chs))!=-1){
bw.write(chs,0,len);
bw.flush();
}
br.close();
bw.close();
}
}
5)
public class CopyFileDemo11 {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new FileReader("F:\\a.txt"));
BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\l.txt"));
String line=null;
while((line=br.readLine())!=null){
int len=Integer.parseInt(line);
bw.write(line,0,len);
bw.flush();
}
br.close();
bw.close();
}
}
复制图片的四种方式:
1)
public class CopyImageDmeo1 {
public static void main(String[] args) throws IOException{
FileInputStream fis = new FileInputStream("F:\\jietu.JPG") ;
FileOutputStream fos = new FileOutputStream("D:\\study1.JPG") ;
byte[] bys = new byte[1024] ;
int len = 0 ;
while((len=fis.read(bys))!=-1){
fos.write(bys, 0, len) ;
}
fis.close() ;
fos.close() ;
}
}
2)
public class CopyImageDmeo2 {
public static void main(String[] args) throws IOException{
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("F:\\jietu.JPG"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\study2.JPG"));
byte[] bys=new byte[1024];
int len=0;
while((len=bis.read(bys))!=-1){
bos.write(bys,0,len);
bos.flush();
}
bis.close();
bos.close();
}
}
3)
public class CopyImageDmeo3 {
public static void main(String[] args) throws IOException{
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("F:\\jietu.JPG"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\study3.JPG"));
int by=0;
while((by=bis.read())!=-1){
bos.write(by);
bos.flush();
}
bis.close();
bos.close();
}
}
4)
public class CopyImageDmeo4 {
public static void main(String[] args) throws IOException{
FileInputStream fis = new FileInputStream("F:\\jietu.JPG") ;
FileOutputStream fos = new FileOutputStream("D:\\study4.JPG") ;
int by=0;
while((by=fis.read())!=-1){
fos.write(by);
fos.flush();
}
fis.close();
fos.close();
}
}