我定义了一个方法来使用BufferedInputStream和BufferedOutputStream来复制图片,代码如下:
String fromPath = "D:\\aa.png";
String toPath = "C:\\a.png";
- private static void copyPicByBuffer(String fromPath, String toPath) {
- // TODO Auto-generated method stub
- BufferedInputStream bis = null;
- BufferedOutputStream bos = null;
- try {
- bis = new BufferedInputStream(new FileInputStream("fromPath"));
- bos = new BufferedOutputStream(new FileOutputStream("toPath"));
- byte[] buf = new byte[1024];
- int len = 0;
- while ((len = bis.read(buf)) != -1) {
- bos.write(buf, 0, len);
- bos.flush();
- }
- System.out.println("Finished copying picture by buffer");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- if (bis != null) {
- try {
- bis.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if(bos!=null){
- try {
- bos.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
复制代码
为什么运行的时候提示java.io.FileNotFoundException: fromPath (系统找不到指定的文件。)错误啊!
我确定我指定的路径文件都是存在的啊! |