How do I sort very large files

That isn’t exactly a Java problem. You need to look into an efficient algorithm for sorting data that isn’t completely read into memory. A few adaptations to Merge-Sort can achieve this. Take a look at this: http://en.wikipedia.org/wiki/Merge_sort and: http://en.wikipedia.org/wiki/External_sorting Basically the idea here is to break the file into smaller pieces, sort them (either with … Read more

How can I read all files in a folder from Java?

Use: public void listFilesForFolder(final File folder) { for (final File fileEntry : folder.listFiles()) { if (fileEntry.isDirectory()) { listFilesForFolder(fileEntry); } else { System.out.println(fileEntry.getName()); } } } final File folder = new File(“/home/you/Desktop”); listFilesForFolder(folder); The Files.walk API is available from Java 8. try (Stream<Path> paths = Files.walk(Paths.get(“/home/you/Desktop”))) { paths .filter(Files::isRegularFile) .forEach(System.out::println); } The example uses the try-with-resources … Read more

Is it possible to get the compressed and uncompressed sizes of a file on a btrfs file system?

there is a third party tool that can do this. https://github.com/kilobyte/compsize usage: ayush@devbox:/code/compsize$ sudo compsize /opt Processed 54036 files, 42027 regular extents (42028 refs), 27150 inline. Type Perc Disk Usage Uncompressed Referenced Data 82% 5.3G 6.4G 6.4G none 100% 4.3G 4.3G 4.3G zlib 37% 427M 1.1G 1.1G lzo 56% 588M 1.0G 1.0G

Properly Create and Serve PDF Blob via HTML5 File and URL APIs

jQuery.ajax does not currently support blobs, see this bug report #7248 which is closed as wontfix. However it’s easy to do XHR for blobs without jQuery: var xhr = new XMLHttpRequest(); xhr.open(‘GET’, ‘http://www.grida.no/climate/ipcc_tar/wg1/pdf/tar-01.pdf’, true); xhr.responseType=”blob”; xhr.onload = function(e) { if (this.status == 200) { // Note: .response instead of .responseText var blob = new Blob([this.response], … Read more

In Perl, how do I change, delete, or insert a line in a file, or append to the beginning of a file?

(This is the official perlfaq answer, minus any subsequent edits) The basic idea of inserting, changing, or deleting a line from a text file involves reading and printing the file to the point you want to make the change, making the change, then reading and printing the rest of the file. Perl doesn’t provide random … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)