package homework007;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
public class Text001
{
public static void main(String[] args) throws Exception
{
try
{
//读取
FileInputStream in = new FileInputStream("e:/text.txt");
String str = "";
int i =0;
byte[] b1 = new byte[1024];
while((i=in.read(b1))>0)
{
str+=new String(b1,0,i);
}
in.close();
System.out.println("文件读取完成");
//写入
Scanner sc = new Scanner(System.in);
System.out.println("请输入您要另存的文件全路径");
String str1 = sc.nextLine();
FileOutputStream out = new FileOutputStream(str1);
byte[] b = str.getBytes();
out.write(b);
System.out.println("内容添加成功");
out.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
}
![]()