HTML5 FileReader alternative

Ended up not using FileReader at all, instead I looped through event.files and got each file by files[i] and sent an AJAX request by XHR with a FormData object (worked for me because I decided I don’t need to get the file data): var xhrPool = {}; var dt = e.dataTransfer; var files = (e.files … Read more

How to read a properties file in javascript from project directory?

There is a super simple way to do this, along the lines of sowbug’s answer, but which doesn’t need any XHR or file reading. Step 1. Create resource/config.js like so: gOptions = { // This can have nested stuff, arrays, etc. color: ‘red’, size: ‘big’, enabled: true, count: 5 } Step 2. Include this file … Read more

Reading line-by-line file in JavaScript on client side

Eventually I’ve created new line-by-line reader, which is totally different from previous one. Features are: Index-based access to File (sequential and random) Optimized for repeat random reading (milestones with byte offset saved for lines already navigated in past), so after you’ve read all file once, accessing line 43422145 will be almost as fast as accessing … Read more

Reading multiple files with Javascript FileReader API one at a time

I came up with a solution myself which works. function readmultifiles(files) { var reader = new FileReader(); function readFile(index) { if( index >= files.length ) return; var file = files[index]; reader.onload = function(e) { // get file content var bin = e.target.result; // do sth with bin readFile(index+1) } reader.readAsBinaryString(file); } readFile(0); }

Read a file synchronously in Javascript

You can use the standard FileReaderSync, which is a simpler, synchronous, blocking version of the FileReader API, similar to what you are already using: let reader = new FileReaderSync(); let result_base64 = reader.readAsDataURL(file); console.log(result_base64); // aGV5IHRoZXJl… Keep in mind though that this is only available in worker threads, for obvious reasons. If you need a … Read more

Difference between java.io.PrintWriter and java.io.BufferedWriter?

PrintWriter gives more methods (println), but the most important (and worrying) difference to be aware of is that it swallows exceptions. You can call checkError later on to see whether any errors have occurred, but typically you’d use PrintWriter for things like writing to the console – or in “quick ‘n dirty” apps where you … Read more