Skip to content

Tag: file-io

BufferInputStream vs ByteArrayInputStream

Here are three ways to read an entire file into memory before processing it: Approach A: Approach B: Approach C: Why would I prefer one approach over another? Are there any specific use-cases that call for one approach over another? Why not use a fixed-length byte[] instead? Answer Unless you need anything sp…

Changing the directory path’s forward slash to backslash

I’m using the JFile chooser, and trying to import a pdf file but; System.out.println(filelist); perfectly prints the desired outcome with forward slashes; C:/Users/raz/Documents/2pg.pdf but the doc gives an error with backslashes; java.io.FileNotFoundException: C:UsersrazDocuments2pg.pdf (The filename, …

How to write an S3 object to a file?

What’s the fastest way to write an S3 object (of which I have the key) to a file? I’m using Java. Answer While IOUtils.copy() and IOUtils.copyLarge() are great, I would prefer the old school way of looping through the inputstream until the inputstream returns -1. Why? I used IOUtils.copy() before …