I had no problem getting these characters (eg. 戦う) to display properly while I was running the program within Netbeans. Earlier, I added the parameter -J-Dfile.encoding=UTF-8 to the netbeans.conf file.
Essentially, I am creating a program to append data onto the end of a text file. Whilst running through Netbeans, the data would be saved correctly and the characters would show up when I opened the file. However, when I run the .jar independent of Netbeans (or run a built .exe) it just saves the characters to the file as '????'.
The code below shows the method that appends data onto the file. boxValue[] stores the String data that I am appending. When running the program through Netbeans, the file output would look like this when I opened the file:
食べる to eat - Plain: Present たべる 5 食べる
Running the program independently, without Netbeans, would produce this in the text file:
??? to eat - Plain: Present ??? 5 ???
private void prepareFile(String[] boxValue, boolean ruVerbIN, String addressIN){
try
{
int counter = 0;
int counter2;
if(ruVerbIN == false)
{
counter2 = 63;
}
else
{
counter2 = 55;
}
File wordFile = new File(addressIN);
FileWriter fileWriter = new FileWriter(wordFile, true);
BufferedWriter buffer = new BufferedWriter(fileWriter);
PrintWriter printWriter = new PrintWriter(buffer);
while(counter <= counter2)
{
printWriter.println(boxValue[counter]);
counter++;
}
printWriter.close();
counter = 0;
outputTextBox.setText("Export successful.");
}
catch(IOException e)
{
outputTextBox.setText("There was an error. Are you sure you entered the directory correctly? For example:" + "\n\n" + "\"C:\\\\Users\\\\Jayden\\\\Documents\\\\FLTR\\\\FLTR Data\\\\Japanese_Words.csv\"");
}
}