我想在目标文件中复制源文件但是如何通过choosefiler选择文本字段中文件的完整路径并将其放在此代码中

时间:2015-11-03 21:36:57

标签: java swing

我想在目标文件中复制源文件,知道这两个文件必须由choosefiler选择并在文本字段中将其过去以查看完整路径,以便如何在文本字段中选择文件的完整路径choosefiler并将其放在此代码中

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Main {
   public static void main(String[] args) {

      FileInputStream fis = null;
      FileOutputStream fos = null;

      try {

         fis = new FileInputStream(new File(""));
         fos = new FileOutputStream(new File(""));

         byte[] buf = new byte[8];

         int n = 0;

         while ((n = fis.read(buf)) >= 0) {

            for (byte bit : buf) {
               System.out.print("\t" + bit + "(" + (char) bit + ")");
               System.out.println("");
            }

            buf = new byte[8];

         }
         System.out.println("Copie terminée !");
} catch (FileNotFoundException e) {

         e.printStackTrace();
      } catch (IOException e) {

         e.printStackTrace();
      } finally {


         try {
            if (fis != null)
               fis.close();
         } catch (IOException e) {
            e.printStackTrace();
         }

         try {
            if (fos != null)
               fos.close();
         } catch (IOException e) {
            e.printStackTrace();
         }
      }
   }
}

0 个答案:

没有答案