java - How do I load a FileResource into a byte array? -
i have file called data.dat
load byte[]
in vaadin. data file need load , manipulate based on user's input.
i tried:
string basepath = vaadinservice.getcurrent().getbasedirectory().getabsolutepath(); fileresource resource = new fileresource(new file(basepath + my_data_file));
the problem don't know how manipulate resource
extract byte[]
. see lots of information how put images , on ui components, how stream user generated pdf, , on, can't seem find examples on how load own data file manipulate within code...
from docs of vaadin have:
java.io.file getsourcefile() gets source file.
or
downloadstream getstream() gets resource stream.
and in downloadstream
:
java.io.inputstream getstream() gets downloadable stream.
so can operate on file
or inputstream
read contents of fileresource
for example in java 8:
byte[] bytes = files.readallbytes(paths.get(resource.getsourcefile().getabsolutepath()));
Comments
Post a Comment