I have a problem when I create a file using the Shift-JIS charset.
This is an example of text that I want write into a txt file:
繰戻_日経選挙システム保守2019年1月10日~;[2019年度更新]横浜第1DCコロケ―ション(2ラック)
Using Shift-JIS charset, into the file I find two '?' instead of ~ and ―:
繰戻_日経選挙システム保守2019年1月10日?;[2019年度更新]横浜第1DCコロケ?ション(2ラック)
Using UTF-8 charset, into the file I find (all correct):
繰戻_日経選挙システム保守2019年1月10日~;[2019年度更新]横浜第1DCコロケ―ション(2ラック)
This is my code:
package it.grupposervizi.easy.ef.etl.elaboration;
import com.nimbusds.jose.util.StandardCharset;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.io.FileUtils;
public class TestShiftJIS {
private static final String TEXT = "繰戻_日経選挙システム保守2019年1月10日~;[2019年度更新]横浜第1DCコロケ―ション(2ラック)";
private static final String DIRECTORY = "C:\\temp\\japan\\";
private static final String SHIFT_JIS = "Shift-JIS";
private static final String UTF_8 = StandardCharset.UTF_8.name();
private static final String EXTENSION = ".txt";
public static void main(String[] args) {
final List<String> charsets = Arrays.asList(SHIFT_JIS, UTF_8);
charsets.forEach(c -> {
final String fName = DIRECTORY + c + EXTENSION;
File file = new File(fName);
try {
FileUtils.writeStringToFile(file, TEXT, Charset.forName(c));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
System.out.println("End Test");
}
}
Do you have any idea why these two chars are not included into the Shift-JIS charset?