运行时错误:java.rmi.NoSuchObjectException:表中没有此类对象

时间:2014-09-12 12:02:13

标签: java file-transfer

我试图从服务器获取文件列表并将其复制到目录。 并且此错误提示。

java.rmi.NoSuchObjectException: no such object in table

at javafxhomeui_1.HomeUI_2Controller.writeFileToLocalHDD(HomeUI_2Controller.java:427)
at javafxhomeui_1.HomeUI_2Controller.initialize(HomeUI_2Controller.java:312)

HomeUI_2Controller.java

    RemoteInputStream ris= null;
    File[] iconlist=null;
    try {
        File appicon=new File("D:\\SERVER\\Server Content\\Apps\\icons");
        iconlist=appicon.listFiles();
        for (File file1 : iconlist) {
             ris = downloadcontroller.getFile(file1.getAbsolutePath());
             System.out.println(file1.getName());
        }

    } catch (Exception ex) {
        Logger.getLogger(HomeUI_2Controller.class.getName()).log(Level.SEVERE, null, ex);
    }

try {
        for (File file1 : iconlist) {
            //System.out.println("D:\\client\\Temp\\"+file1.getName());

 /*line:312 */            writeFileToLocalHDD(ris,"D:\\client\\Temp\\"+file1.getName());
        }

    } catch (Exception ex) {
        Logger.getLogger(HomeUI_2Controller.class.getName()).log(Level.SEVERE, null, ex);
    }

public static void writeFileToLocalHDD(RemoteInputStream inFile, String fileLocation) throws IOException {
    // wrap RemoteInputStream as InputStream (all compression issues are dealt
    // with in the wrapper code)
/* line:427*/ InputStream istream = RemoteInputStreamClient.wrap(inFile);
    BufferedInputStream bis = new BufferedInputStream(istream);


    //downloaded file...
    File file = new File(fileLocation);



    if (!file.exists()) {
        file.createNewFile();
    }


    FileOutputStream fileOutputStream = new FileOutputStream(file);
    FileChannel channel = fileOutputStream.getChannel();

    byte b[] = new byte[1024];
    long startTime = System.currentTimeMillis();
    while (bis.available()>0) {
        bis.read(b);
        System.out.println((System.currentTimeMillis() - startTime)/1000);
        ByteBuffer buffer = ByteBuffer.wrap(b);
        channel.write(buffer);
    }


    bis.close();
    fileOutputStream.flush();
    channel.close();
    fileOutputStream.close();


}

/////////////////////////////////////////////// /

public RemoteInputStream getFile(String fileName) throws IOException {
    // create a RemoteStreamServer (note the finally block which only releases
    // the RMI resources if the method fails before returning.)
    //read data
    RemoteInputStreamServer istream = null;
    try {
        File file = new File(fileName);
        System.out.println(file.exists());
        FileInputStream fileInputStream = new FileInputStream(file);

        BufferedInputStream bufferedInputStream = new BufferedInputStream(
                fileInputStream);
        istream = new SimpleRemoteInputStream(bufferedInputStream);
        // export the final stream for returning to the client

        //send data
        RemoteInputStream result = istream.export();
        // after all the hard work, discard the local reference (we are passing
        // responsibility to the client)
        istream = null;
        return result;
    } finally {
        // we will only close the stream here if the server fails before
        // returning an exported stream
        if (istream != null) {
            istream.close();
        }
    }
}

////////////////////////////////////

1 个答案:

答案 0 :(得分:0)

rmi适用于存根和骨架结构。 抛出的异常与rmi Registry有关。找不到该对象,因为它不能从RMI resistry获得。 如果尝试在远程虚拟机中不再存在的对象上调用方法,则抛出NoSuchObjectException javaDoc of the Exception thrown