Java create .docx file from byte array -


i read .docx file byte array, when tried save again .docx file, file couldn't open.

can explain why?

public static void main(string[] args) throws ioexception {     byte[] data = readfile("test.docx");     system.out.println(data.length);      try (fileoutputstream fos = new fileoutputstream("testcopy.docx")) {         fos.write(data);     } } 

and here readfile method

public static byte[] readfile(string filepath) throws filenotfoundexception, ioexception {     file file = new file(filepath);     byte[] bytes = new byte[(int) file.length()];     try (datainputstream datainputstream = new datainputstream(new bufferedinputstream(new fileinputstream(filepath)))) {         datainputstream.readfully(bytes);     }      return bytes; } 

you should difference between datainputstream , fileinputstream.

try using fileinputstream instead of datainputstream , see how works.

try (fileinputstream fileinputstream = new fileinputstream(filepath)) {             fileinputstream.read(bytes); } 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -