1

あるディレクトリから別のディレクトリにファイルを移動する他の方法があるかどうか疑問に思います。私のプログラムのスニペットを以下に示します。Javaでファイルを移動する効率的な方法があるはずだと思います。よろしければご覧いただき、回答をお願いいたします。ありがとう!

public static void movFile(File pathFromMove,File pathToMove,File fileToMove)    //helper method 2
{

    String absPathFile2= pathToMove.getAbsolutePath() + "\\"+fileToMove.getName();                                                              //{

    InputStream inStream = null;
    OutputStream outStream = null;

    try
    {
        //System.out.println("i am here no1");
        inStream= new FileInputStream(fileToMove);
        outStream=new FileOutputStream(absPathFile2);
        byte[] buffer = new byte[1024];


        int length;
        while (( length = inStream.read(buffer)) > 0)
        {

            outStream.write(buffer, 0, length);
            //System.out.println("i am here no2");

        }
      inStream.close();
        outStream.close();
        fileToMove.delete();            //to delete the original files
    //  System.out.println("i am here no3");

    }
    catch(IOException e)
    {
        //System.out.println("i am here no4");

        e.printStackTrace();
    }

}
4

1 に答える 1