public static void main(String[] args) {
File file=new File("c:\\test.txt")
BufferedReader read=null
BufferedWriter writer=null
try {
writer=new BufferedWriter(new FileWriter("c:\\zwm.txt"))
} catch (IOException e1) {
e1.printStackTrace()
}
try {
read=new BufferedReader(new FileReader(file))
String tempString = null
while((tempString=read.readLine())!=null){
writer.append(tempString)
writer.newLine()//换行
writer.flush()//需要及时清掉流的缓坦蔽冲区,万一文件过大就有可能无法写入了
}
read.close()
writer.close()
System.out.println("文件写入完成...")
} catch (IOException e) {
e.printStackTrace()
}
}
}
这个例子是将一个文件的东西,让闭州写入到另一个文件里面去。
StreamWriter sw = new StreamWriter(filename)stream.CopyTo(sw.BaseStream)
sw.Flush()
sw.Close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)