Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://howtodoinjava.com/java/io/java-read-file-to-string-examples/
- // https://stackoverflow.com/questions/19486077/java-fastest-way-to-read-through-text-file-with-2-million-lines
- // http://net-informations.com/q/faq/memory.html
- // http://www.java2s.com/Tutorials/Java/java.nio.file/Files/Java_Tutorial_Files.htm
- import java.io.*;
- import java.nio.file.*;
- import java.nio.charset.Charset;
- import java.nio.charset.StandardCharsets;
- import java.util.*;
- //import org.apache.commons.io.*;
- public class m {
- public static void main(String[] args) throws InterruptedException {
- try {
- byte[] bytes = Files.readAllBytes(Paths.get(args[0])); // // a "legjobb" memóriafoglalás: 164 MB -> 340 MB
- //String str = new String(bytes, StandardCharsets.UTF_8);
- //List<String> lines = Files.readAllLines(Paths.get(args[0]),Charset.forName("ISO-8859-2")); // túlzott memóriafoglalás: 164 MB -> 775 MB
- //String str1 = new String ( Files.readAllBytes( Paths.get(args[0]) ) ); // túlzott memóriafoglalás: 164 MB -> 664 MB
- //String str2 = Files.readString(Paths.get(args[0])); // only Java 11
- //String str3 = FileUtils.readFileToString(args[0], "utf-8"); // apache
- //String str4 = new Scanner(new File(args[0])).useDelimiter("\\Z").next(); // irreális memóriafoglalás: 164 MB -> 2086 MB
- /*BufferedReader buf = new BufferedReader(new InputStreamReader(new FileInputStream(args[0])));
- StringBuilder sb = new StringBuilder();
- String line = "";
- while ( (line = buf.readLine()) != null){
- sb.append(line).append("\n");
- }*/ // 164 MB-> 808 MB & java.lang.NullPointerException
- /*BufferedReader br = new BufferedReader(new FileReader(args[0]), 8192 * 8192);
- StringBuilder sb = new StringBuilder();
- String thisLine="";
- while ((thisLine = br.readLine()) != null) {
- sb.append(thisLine).append("\n");
- }*/ // 164 MB -> 1112 MB
- //FileReader fileReader = new FileReader(new File(args[0])); ... while read() is -1
- //InputStreamReader isr = new InputStreamReader(new FileInputStream(args[0]),Charset.defaultCharset().name()); // 164 MB -> 340 MB
- //InputStreamReader isr = new InputStreamReader(new FileInputStream(args[0]),Charset.forName("ISO-8859-2")); // 164 MB -> 340 MB
- //InputStreamReader isr = new InputStreamReader(new FileInputStream(args[0]),StandardCharsets.UTF_8); // 164 MB -> 340 MB
- // input stream reader is closed
- } catch (Exception e) {
- //e.printStackTrace();
- System.out.println(e);
- }
- Thread.sleep(10000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement