I have a .txt with some kind of "ASCII-Art" that I want to display in the cmd console. The characters are UTF-8, but the default Charset of my JVM is windows-1252. I tried to convert the UTF-8 chars to a bytearray and then convert the bytearray back to a String with set UTF-8 encoding. With this approach, some chars get depicted correctly on the cmd console, but many are just replaced by a '?' and the text stops miraculously in the second line (the "ASCII-Art" is much longer).
One of those UTF-8 chars that were replaced by '?' is '∩'. The program worked fine for my IDE though, because there the default Charset is UTF-8.
Is it possible to write a phrase in my java program that tells the JVM to just switch to UTF-8 Charset for this program? Or what else could I change so I get this piece of Art in my cmd console?
import java.io.File;
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
public class ASCIIfromtxt {
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
File artFile = new File("C:/Users/MyName/IdeaProjects/ASCIIArt from Textfile/out/production/ASCIIArt from Textfile/Art.txt");
Scanner scan = new Scanner(artFile);
while (scan.hasNextLine()) {
String nextLineString = scan.nextLine();
byte[] nextLineBytes = nextLineString.getBytes();
String win1252Str = new String(nextLineBytes, "UTF-8");
System.out.println(win1252Str);
}
}
}