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

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

SSLHandShakeException No Appropriate Protocol

In $JRE/lib/security/java.security: jdk.tls.disabledAlgorithms=SSLv3, TLSv1, RC4, DES, MD5withRSA, DH keySize < 1024, \ EC keySize < 224, 3DES_EDE_CBC, anon, NULL This line is enabled, after I commented out this line, everything is working fine. Apparently after/in jre1.8.0_181 this line is enabled. My Java version is “1.8.0_201.

Java using scanner enter key pressed

This works using java.util.Scanner and will take multiple “enter” keystrokes: Scanner scanner = new Scanner(System.in); String readString = scanner.nextLine(); while(readString!=null) { System.out.println(readString); if (readString.isEmpty()) { System.out.println(“Read Enter Key.”); } if (scanner.hasNextLine()) { readString = scanner.nextLine(); } else { readString = null; } } To break it down: Scanner scanner = new Scanner(System.in); String readString = … Read more

Specific difference between bufferedreader and filereader

First, You should understand “streaming” in Java because all “Readers” in Java are built upon this concept. File Streaming File streaming is carried out by the FileInputStream object in Java. // it reads a byte at a time and stores into the ‘byt’ variable int byt; while((byt = fileInputStream.read()) != -1) { fileOutputStream.write(byt); } This … Read more