bytearray - ODT File to Byte Array Java -
i trying odt file bytearray uploadting server. think found way how here :how can generate byte array odt file java .
but 1 problem have how can use on file open in writer because want happens when press button?
tried adress file:
//abspeichern des documents im temp ordner string storeurl = "file:///c:/windows/temp/test.odt"; xmodel xdocmodel = this.frame.getcontroller().getmodel(); xtextdocument xtextdocument = (xtextdocument) unoruntime.queryinterface(xtextdocument.class, xdocmodel); xstorable xstorable = (xstorable) unoruntime.queryinterface(xstorable.class, xtextdocument); propertyvalue[] storeprops = new propertyvalue[1]; storeprops[0] = new propertyvalue(); storeprops[0].name = "overwrite"; storeprops[0].value = new boolean(true); try { xstorable.storetourl(storeurl, storeprops); } catch (com.sun.star.io.ioexception ex) { logger.getlogger(optionpagedemo.class.getname()).log(level.severe, null, ex); } //konvertieren in byte[] path test = paths.get("c:/windows/temp/test.odt"); byte[] data = files.readallbytes(test);
but not seem work.
so maybe can tell me how can adress file :)
save odt file disk first. following code works on machine:
import com.sun.star.frame.xstorable; import java.net.url; import java.nio.file.files; import java.nio.file.path; import java.nio.file.paths;
in main routine:
string storeurl = "file:///c:/users/jimstandard/desktop/test.odt"; xstorable xstorable = (xstorable) unoruntime.queryinterface( xstorable.class, xtextdocument); propertyvalue[] storeprops = new propertyvalue[1]; storeprops[0] = new propertyvalue(); storeprops[0].name = "overwrite"; storeprops[0].value = new boolean(true); try { xstorable.storetourl(storeurl, storeprops); } catch (com.sun.star.io.ioexception ex) { ex.printstacktrace(system.err); system.exit(1); } try { url url = new url(storeurl); // path testpath = paths.get(url.touri()); byte[] data = files.readallbytes(testpath); system.out.println("length = " + data.length); } catch (java.io.ioexception ex) { ex.printstacktrace(system.err); system.exit(1); } catch (urisyntaxexception ex) { ex.printstacktrace(system.err); system.exit(1); }
Comments
Post a Comment