File Path on RMI Server

I have a simple project with a client and server connected via RMI. The server creates an XML file, converts it and saves it as an html file. (currently everything works on localhost)

Now the client should have access to this specific file and display it in the browser, but I do not know how to access the correct file / file path.

The server converts xml to html and saves it

    public void transform() throws RemoteException {
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Source xsldoc = new StreamSource("style.xsl");
    Source xmldoc = new StreamSource(getData().getFile());

    getData().setHmtlFile(new File("htmlconvert.html"));

    try {
        OutputStream htmlFile = new FileOutputStream(getData().getHmtlFile());

        Transformer tr = tFactory.newTransformer(xsldoc);
        tr.transform(xmldoc, new StreamResult(htmlFile));

    } catch (FileNotFoundException | TransformerException e) {
        e.printStackTrace();
    }

}

Client opens file in browser

public void openBrowser() {
    try {
        client.lookup.transform();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    try {
        Desktop.getDesktop().open(client.lookup.getData().getHmtlFile());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Exception thrown

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: File: htmlconvert.html does not exist.

+4
source share

Source: https://habr.com/ru/post/1669649/


All Articles