用什么方法可以实现TXT之间的写入?
package www_3;
import *;
public class CopyFile {
public static void main(String[] args) {
String file1 = " ", file2 = " ";
int ch;
long cnt = 0;
if (args.length == 2) {
if (args[0].equals(args[1])) {
System.out.println("源文件和目标文件名不能相同");
System.exit(0);
} else {
file1 = args[0];
file2 = args[1];
}
} else {
System.out.println("请指定源文件名和目标文件名!");
System.exit(0);
}
try {
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);
cnt = fis.available();
while ((ch = fis.read()) != -1) {
System.out.write(ch);
fos.write(ch);
}
fis.close();
fos.close();
} catch (FileNotFoundException e) {
System.out.println("源文件:未找到!");
System.exit( -1);
} catch (IOException e) {
System.out.println(e.toString());
}
System.out.println("\n复制文件完成,共" + cnt + "个字节!");
}
}
import *;
public class CopyFile {
public static void main(String[] args) {
String file1 = " ", file2 = " ";
int ch;
long cnt = 0;
if (args.length == 2) {
if (args[0].equals(args[1])) {
System.out.println("源文件和目标文件名不能相同");
System.exit(0);
} else {
file1 = args[0];
file2 = args[1];
}
} else {
System.out.println("请指定源文件名和目标文件名!");
System.exit(0);
}
try {
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);
cnt = fis.available();
while ((ch = fis.read()) != -1) {
System.out.write(ch);
fos.write(ch);
}
fis.close();
fos.close();
} catch (FileNotFoundException e) {
System.out.println("源文件:未找到!");
System.exit( -1);
} catch (IOException e) {
System.out.println(e.toString());
}
System.out.println("\n复制文件完成,共" + cnt + "个字节!");
}
}
这个程序是实现TXT之间的覆盖,如果想实现 把一个txt里面的内容复制到另一个txt中,而不覆盖,用什么方法?