没有。
File类中的renameTo(File)起到转移的功能。复制文件也就几行代码而以(复杂一点是的文件夹复制功能),如:
public static void fileCopy(){
try{
String fileName = "c:/mytest.txt";
byte[] iobuff = new byte[1024];
int bytes; FileInputStream fis = new FileInputStream(fileName);
FileOutputStream fos = new FileOutputStream("CopyOf_" + fileName); while ( (bytes = fis.read(iobuff)) != -1) {
fos.write(iobuff, 0, bytes);
}
fis.close();
fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
File类中的renameTo(File)起到转移的功能。复制文件也就几行代码而以(复杂一点是的文件夹复制功能),如:
public static void fileCopy(){
try{
String fileName = "c:/mytest.txt";
byte[] iobuff = new byte[1024];
int bytes; FileInputStream fis = new FileInputStream(fileName);
FileOutputStream fos = new FileOutputStream("CopyOf_" + fileName); while ( (bytes = fis.read(iobuff)) != -1) {
fos.write(iobuff, 0, bytes);
}
fis.close();
fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
/**
* @author 张昊
* Created on 2004-11-30
*/
import java.io.*;
import java.util.*;public class FileUtil { /**
* 拷贝文件
* @param in 源文件,包括整个文件实体
* @param out 目的文件,该文件对象只有文件路径与文件名
* @throws IOException 如果发生输入输出错误,如无源文件、路径错误等
*/
public static void CopyFile(File in, File out) throws IOException {
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();
} /**
* 将文件转换为字符串
* @param in 源文件,包括整个文件实体
* @throws IOException 如果发生输入输出错误,如无源文件、路径错误等
*/
public static String FileToStr(File in) throws IOException {
FileInputStream fis = new FileInputStream(in);
String outStr = null;
byte[] buf = new byte[1024];
int i = 0;
while ((i = fis.read(buf)) != -1) {
outStr += new String(buf);
}
fis.close();
return outStr;
} /**
* 将文件转换为字符串
* @param in 源文件的文件名,包括文件的完整路径
* @throws IOException 如果发生输入输出错误,如无源文件、路径错误等
*/
public static String FileToStr(String in) throws IOException {
return FileToStr(new File(in));
} /**
* 将文件内容存放到集合中
* @param fileName 文件名
* @return 返回一个集合
* @throws IOException 如果读文件出错时
* 将文件的每一行做为集合的数据项
*/
public static List FileToList(String fileName) throws IOException {
File file = new File(fileName);
return FileToList(file);
} /**
* 将文件内容存放到集合中
* @param file 文件对象
* @return 返回一个集合
* @throws IOException 如果读文件出错时
* 将文件的每一行做为集合的数据项
*/
public static List FileToList(File file) throws IOException {
List list = new ArrayList();
String read;
FileReader fileread=new FileReader(file);
BufferedReader bufread=new BufferedReader(fileread);
int counter = 0;
while((read=bufread.readLine())!=null)
{
if(read.equals("")) continue;
list.add(read);
}
return list; }
}是的Java API没有提供
please use NIO, it's a shortcut.
here is an example belowing:
---------------------------------package niotest;import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;/**
*
* @author takecare
*
* PURPOSE: copy file using NIO Channel
*
*/
public class NIOCopyFile {
public static void main(String[] args) throws IOException,
FileNotFoundException {
FileInputStream inData = new FileInputStream("input.dat");
FileChannel inChannel = inData.getChannel();
FileOutputStream opData = new FileOutputStream("output.dat");
FileChannel opChannel = opData.getChannel();
inChannel.transferTo(0, inChannel.size(), opChannel); inChannel.close();
inData.close();
opChannel.close();
opData.close();
}
}