Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading/Writing a Binary file!  RSS feed

 
Julia Irving
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to open some Word and Excel documents with my JSP. I was told that I can use Java's I/O methods for binary files (while paying attention to the MIME type) since I will simply be reading the files and then serving them to the user. There are so many read and write methods. Which methods are best for reading and writing entire binary files? I would greatly appreciate any help on this. Thanks in advance.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never done this before, but we've had a couple of people asking about how to read these types of files, and they've been referred to the Jakarta POI project.
If you are just reading the file, what I would do is create a byte array that is the length of the file in bytes (which you can determine by File.length). Then use the FileInputStream.read( byte[] b ) method to read in the bytes from the file.
How you are displaying the file is a different problem. Are you trying to display the data within your jsp page?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!