JAVA IO流小实例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA IO流小实例相关的知识,希望对你有一定的参考价值。
package demo;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
public class Demo04{
public static void main(String[] args) throws IOException{
File fw = new File("E:\\tt.txt");
File fr = new File("F:\\PB学习\\pb.txt");
Demo04.FileWriter(fr, fw);
}
public static void FileWriter(File in,File ot) throws IOException{
if(!in.exists()){
in.getParentFile().mkdirs();
in.createNewFile();
}
if(!ot.exists()){
ot.getParentFile().mkdirs();
ot.createNewFile();
}
InputStreamReader isr=new InputStreamReader(new FileInputStream(in));
OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream(ot),"utf-8");
BufferedReader br = new BufferedReader(isr);
BufferedWriter bw = new BufferedWriter(osw);
char[] buffer = new char[1024];
int c;
while ((c = br.read(buffer,0,1024)) != -1) {
bw.write(buffer,0,c);
}
br.close();
bw.close();
System.out.println("OK");
}
}
以上是关于JAVA IO流小实例的主要内容,如果未能解决你的问题,请参考以下文章