6 个解决方案
#1
关注
#2
很容易的。
BufferedReader in = new BufferedReader(new FileReader("源文件名"));
BufferedWriter out = new BufferedWriter(new FileWriter(”目标文件名"),true);
String str;
while( (str = in.readLine())!= -1)
{
out.write(str);
}
.......
BufferedReader in = new BufferedReader(new FileReader("源文件名"));
BufferedWriter out = new BufferedWriter(new FileWriter(”目标文件名"),true);
String str;
while( (str = in.readLine())!= -1)
{
out.write(str);
}
.......
#3
import java.io.*;
public class jCOPY {
public static void main(String args[]){
try {
jCOPY j = new jCOPY();
j.CopyFile(new File(args[0]),new File(args[1]));
}
catch (Exception e) {
e.printStackTrace();
}
}
public void CopyFile(File in, File out) throws Exception {
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while((i=fis.read(buf))!=-1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
}
}
public class jCOPY {
public static void main(String args[]){
try {
jCOPY j = new jCOPY();
j.CopyFile(new File(args[0]),new File(args[1]));
}
catch (Exception e) {
e.printStackTrace();
}
}
public void CopyFile(File in, File out) throws Exception {
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while((i=fis.read(buf))!=-1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
}
}
#4
我想先知道怎么拷贝一个文件,用什么类
#5
我觉得拷贝文件用FileInputStream,FileOutputStream较好,不必要用BufferedReader在内存中缓冲文件。
#6
路人甲的程序能拷贝整个目录吗??我去试试!
#1
关注
#2
很容易的。
BufferedReader in = new BufferedReader(new FileReader("源文件名"));
BufferedWriter out = new BufferedWriter(new FileWriter(”目标文件名"),true);
String str;
while( (str = in.readLine())!= -1)
{
out.write(str);
}
.......
BufferedReader in = new BufferedReader(new FileReader("源文件名"));
BufferedWriter out = new BufferedWriter(new FileWriter(”目标文件名"),true);
String str;
while( (str = in.readLine())!= -1)
{
out.write(str);
}
.......
#3
import java.io.*;
public class jCOPY {
public static void main(String args[]){
try {
jCOPY j = new jCOPY();
j.CopyFile(new File(args[0]),new File(args[1]));
}
catch (Exception e) {
e.printStackTrace();
}
}
public void CopyFile(File in, File out) throws Exception {
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while((i=fis.read(buf))!=-1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
}
}
public class jCOPY {
public static void main(String args[]){
try {
jCOPY j = new jCOPY();
j.CopyFile(new File(args[0]),new File(args[1]));
}
catch (Exception e) {
e.printStackTrace();
}
}
public void CopyFile(File in, File out) throws Exception {
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while((i=fis.read(buf))!=-1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
}
}
#4
我想先知道怎么拷贝一个文件,用什么类
#5
我觉得拷贝文件用FileInputStream,FileOutputStream较好,不必要用BufferedReader在内存中缓冲文件。
#6
路人甲的程序能拷贝整个目录吗??我去试试!