Hello i was wondering to convert text in java to ascii
To convert text to ASCII you can do
String text = "Hello World!";
byte[] ascii = text.getBytes("US-ASCII");
you mean smth like
String str;
int[] asciiCodes = new int[str.length()];
for (int i = 0; i < str.length(); i ++) {
asciiCodes[i] = (int)str.charAt(i);
}
?
You question is not very clear, but I guess you may want to write text using an OutputStreamWriter
created with the US-ASCII character set:
OutputStream out = new FileOutputStream("ascii-file.txt");
Writer writer = new OutputStreamWriter(out, "US-ASCII");
writer.write("A string with accents éèà");
writer.close();
精彩评论