NuMs NuMs - 1 year ago 88
Java Question

Alt-codes only work in Java string when run within Netbeans

I have a small java program that reads a given file with data and converts it to a csv file.

I've been trying to use the arrow symbols: ↑, ↓, → and ← (Alt+24 to 27) but unless the program is run from within Netbeans (Using F6), they will always come out as '?' in the resulting csv file.

I have tried using the unicodes, eg "\u2190" but it makes no difference.

Anyone know why this is happening?

As requested, here is a sample code that gives the same issue. This wont work when run using the .jar file, just creating a csv file containing '?', however running from within Netbeans works.


public class Sample {

String fileOutName = "testresult.csv";

* @param args the command line arguments
public static void main(String[] args) throws FileNotFoundException {
Sample test = new Sample();


public void saveTheArrow() {
try (PrintWriter outputStream = new PrintWriter(fileOutName)) {
catch (FileNotFoundException e) {
// Do nothing

Answer Source

new PrintWriter(fileOutName) uses the default charset of the JVM - you may have different defaults in Netbeans and in the console.

Google Sheet uses UTF_8 according to this thread so it would make sense to save your file using that character set:

Files.write(Paths.get("testresult.csv"), "←".getBytes(UTF_8));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download