使用Java文件流将"E:\\kj.txt"文件中的内容复制到"D:\\new.txt".
展开全部
import java.io.*;
public class copy
{
public static void main(String args[]) throws IOException
{
int i;
FileReader fr;
FileWriter fw;
try
{
fr=new FileReader("E:\\kj.txt");
}
catch(FileNotFoundException e)
{
System.out.println("not found this file");
return;
}
try
{
fw=new FileWriter("D:\\new.txt");
}
catch(FileNotFoundException e)
{
System.out.println("error");
return;
}catch(IOException e){
System.out.println("wrong");
return;
}
try
{
i=fr.read();
while(i!=-1)
{
fw.write(i);
i=fr.read();
}
fr.close();
fw.close();
}
catch(IOException e)
{
System.out.println("error");
}
}
}
2016-07-07 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
import java.io.*;
/**
* Created by liguoqing on 2016/3/28.
*/
public class ReadTxtFile {
public static void readTxt(String filePath) {
try {
File file = new File(filePath);
if(file.isFile() && file.exists()) {
InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8");
BufferedReader br = new BufferedReader(isr);
String lineTxt = null;
while ((lineTxt = br.readLine()) != null) {
System.out.println(lineTxt);
}
br.close();
} else {
System.out.println("文件不存在!");
}
} catch (Exception e) {
System.out.println("文件读取错误!");
}
}
public static void main(String[] args) {
String filePath = "D:\\test\\我.txt";
readTxt(filePath);
}
/**
* Created by liguoqing on 2016/3/28.
*/
public class ReadTxtFile {
public static void readTxt(String filePath) {
try {
File file = new File(filePath);
if(file.isFile() && file.exists()) {
InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8");
BufferedReader br = new BufferedReader(isr);
String lineTxt = null;
while ((lineTxt = br.readLine()) != null) {
System.out.println(lineTxt);
}
br.close();
} else {
System.out.println("文件不存在!");
}
} catch (Exception e) {
System.out.println("文件读取错误!");
}
}
public static void main(String[] args) {
String filePath = "D:\\test\\我.txt";
readTxt(filePath);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询