写一个测试缓冲流,然后eclipse不让我添加文件的路径。
全代码:
package itdsj;
import java.io.BufferedOutputStream;
import java.io.BufferedInputStream;
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.OutputStream;
/**加入了字节缓冲流:
*
* 文件(任何文件)输入输出流:文件处于电脑上,java要通过操作
* 系统访问它。所以要每次用完都必须释放资源
* 1.创建源
* 2.选择流
* 3.操作
* 4.释放资源
* @author Mr xing
*
*/
public class BufferedInputStream {
public static void main(String[] args) {
copyAllFile("D:/develop/workspace/Test/abc.txt","b.xtx");
}
public static void copyAllFile(String srcFile,String destFile) {
File src = new File(srcFile);
File dest = new File(destFile);
InputStream is = null;
OutputStream os = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
is = new FileInputStream(src);
bis = new BufferedInputStream(is);
os = new FileOutputStream(dest);
bos = new BufferedOutputStream(os);
byte[] lunch = new byte[1024];
int len = -1;
while((len=bis.read(lunch))!=-1) {
os.write(lunch,0,len);
os.flush();//刷新
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
if(null!=is)
{
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(null!=os)
{
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(null!=bis)
{
try {
bis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(null!=bos)
{
try {
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
它始终不让我添加这句话里的is. bis = new BufferedInputStream(is);
谁可以帮忙看看吗?
