JSF copy files

public static int copyFiles(String orgFile, String newFile) throws AccessControlException
    {
       
        String fromFile = orgFile;//+path
                //"C://~//Documents//NetBeansProjects//ProjectJ2MEWebsite//build//web//resources//Creek.jpg";
        String toFile = newFile;//path;
        System.out.println("copy image: "+fromFile+" to "+toFile);
      // Create files from canonical file names.
      File file1 = new File(fromFile);
      File file2 = new File(toFile);

      // Copy file(s).
      try
      {
      // Define and initialize FileReader(s).
      FileImageInputStream inImageFile  = new FileImageInputStream(file1);
      FileImageOutputStream outImageFile = new FileImageOutputStream(file2);

      // Read character-by-character
      int c =0;
      while ((c = inImageFile.read()) != -1) {
        outImageFile.write(c); }

      // Close Stream(s).
      inImageFile.close();
      outImageFile.close();
      //throws all the stream datas
      //System.gc();
      } catch (IOException e) {
          System.out.print("copy file error: "+e.toString());
          return 0;
      }
      return 1;
    }

 

 

it is able to copy all the files( i think), i have tried image, and jar file. it works well.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章