0

あるディレクトリから別のディレクトリにファイルをコピーしようとしていますが、Copy.exe を実行しようとすると例外が発生します。コードの何が問題なのですか?条件が false のときに if ステートメントを含むコードが実行されるのはなぜですか??

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class Ah {
    public static void main(String[] args){
        File from = new File("."+"/original.exe");
        File to = new File("/home/denis/Run/Copy.exe");
        if(!to.exists()) {                
            to.getParentFile().mkdirs();
        }
        if(from.exists()){
            FileChannel is = null;
            try {
                is = new FileInputStream(from).getChannel();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            FileChannel os = null;
            try {
                os = new FileOutputStream(to).getChannel();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                os.transferFrom(is, 0, is.size());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                is.close();
            } catch (IOException e) {
                  // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                os.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        } else {
            for(File ff: new File(".").listFiles()){

            //Why this code is not executed???
            //why the condition is false but if clouse get executed??
            //is the problem caused by something else???
            System.out.print("There is no such file in a current working      directory, except for "+ff+"\n");
        }
      }
    }
}

これは、ターミナルから「/home/denis/Run/Copy.exe」を実行したときに発生する例外です。

 java.io.FileNotFoundException: /home/denis/Run/Copy.exe (Text file busy)
   at gnu.java.nio.channels.FileChannelImpl.open(libgcj.so.10)
   at gnu.java.nio.channels.FileChannelImpl.<init>(libgcj.so.10)
   at gnu.java.nio.channels.FileChannelImpl.create(libgcj.so.10)
   at java.io.FileOutputStream.<init>(libgcj.so.10)
   at java.io.FileOutputStream.<init>(libgcj.so.10)
   at Ah.main(Copy.exe)
Exception in thread "main" java.lang.NullPointerException
   at Ah.main(Copy.exe)

GCJ を使用して実行可能ファイルを作成し、ubuntu v-12 で Java 6 を実行しています

4

0 に答える 0