下面是我根据楼主的意思自己写的程序,实现功能:在Windows中 让用户输入一个文件路径。然后打开读取其中的内容,并别把读取到的写到了 e:\\duqu.txt 中,看看是否能解决楼主的问题呢
- package mytest;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- //import java.io.InputStream;
- import java.io.InputStreamReader;
- public class Copy {
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String str = br.readLine();
- File file = new File(str);
- FileInputStream fis = new FileInputStream(file);
- BufferedInputStream bis = new BufferedInputStream(fis);
- FileOutputStream fos = new FileOutputStream("e:\\duqu.txt");
- BufferedOutputStream bos = new BufferedOutputStream(fos);
- int len = 0;
- byte[] buf = new byte[1024] ;
- while ((len = bis.read(buf)) != -1) {
- bos.write(buf);
-
- }
- br.close();
- bos.close();
- bis.close();
-
- }
- }
复制代码
|