Should I buffer the InputStream or the InputStreamReader?

r1 is more efficient. The InputStreamReader itself doesn’t have a large buffer. The BufferedReader can be set to have a larger buffer than InputStreamReader. The InputStreamReader in r2 would act as a bottleneck. In a nut: you should read the data through a funnel, not through a bottle. Update: here’s a little benchmark program, just … Read more

How to read BufferedReader faster

Using string concatenation in a loop is the classic performance killer (because Strings are immutable, the entire, increasingly large String is copied for each concatenation). Do this instead: StringBuilder builder = new StringBuilder(); String aux = “”; while ((aux = reader.readLine()) != null) { builder.append(aux); } String text = builder.toString();

Read and Write Text in ANSI format

To read a text file with a specific encoding you can use a FileInputStream in conjunction with a InputStreamReader. The right Java encoding for Windows ANSI is Cp1252. reader = new BufferedReader(new InputStreamReader(new FileInputStream(csvFile), “Cp1252”)); To write a text file with a specific character encoding you can use a FileOutputStream together with a OutputStreamWriter. writer … Read more

How to read plain text file in kotlin?

1. Using BufferedReader import java.io.File import java.io.BufferedReader fun main(args: Array<String>) { val bufferedReader: BufferedReader = File(“example.txt”).bufferedReader() val inputString = bufferedReader.use { it.readText() } println(inputString) } 2. Using InputStream Read By Line import java.io.File import java.io.InputStream fun main(args: Array<String>) { val inputStream: InputStream = File(“example.txt”).inputStream() val lineList = mutableListOf<String>() inputStream.bufferedReader().forEachLine { lineList.add(it) } lineList.forEach{println(“> ” + … Read more

How to use BufferedReader in Java [closed]

Try this to read a file: BufferedReader reader = null; try { File file = new File(“sample-file.dat”); reader = new BufferedReader(new FileReader(file)); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } finally { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } }

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