
import java.io.*; |
/* |
* CopyFileContent.java |
* |
* Created on 2006年8月22日, 下午5:37 |
* |
* 文件内容的拷贝(任意文件) |
*/ |
public class CopyFileContent { |
static void copyContent(FileInputStream inObj, FileOutputStream outObj) { |
int copyLen; |
byte[] copyBuf = new byte[1024]; |
try { |
while ((copyLen = inObj.read(copyBuf, 0, 1024)) != -1) { |
String copyStr = new String(copyBuf); |
System.out.println(copyStr); |
outObj.write(copyBuf, 0, copyLen); |
} |
} catch (IOException e) { |
System.out.println("error: " + e); |
} |
} |
public static void main(String[] args) { |
String secondFileName = "d:\\mydir\\secondFile.wmv"; |
String thirdFileName = "d:\\mydir\\thirdFile.wmv"; |
File fileObject = new File(thirdFileName); |
FileInputStream inStream; |
FileOutputStream outStream; |
try { |
fileObject.createNewFile(); |
inStream = new FileInputStream(secondFileName); |
outStream = new FileOutputStream(thirdFileName); |
copyContent(inStream, outStream); |
} catch (FileNotFoundException e) { |
e.printStackTrace(); |
} catch (IOException e) { |
e.printStackTrace(); |
} |
} |
} |



