Помогите, пожалуйста, разобраться, почему в массив аргументов main(String[] args) вместо параметров на русском языке записывает знаки вопроса.
В настройках IDEA везде стоит UTF-8, текстовый файл то же в UTF-8, в языках и региональных настройках (win 7) стоит Россия и русский язык, в файле idea64.exe.vmoptions прописал -Dfile.encoding=UTF-8... Не знаю, что ещё нужно изменить, чтобы идея нормально конвертировала параметры на русском языке?
package com.javarush.task.task18.task1827;
/*
Прайсы
*/
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.StringJoiner;
public class Solution {
public static void main(String[] args) throws Exception {
String mode = args[0];
String productName = args[1];
System.out.println(productName);
String price = args[2];
System.out.println(price);
String quantity = args[3];
System.out.println(quantity);
if ("-c".equals(mode)) {
String fileName = setFileNameFromKeyboard();
String id = setID(fileName);
String result = prepareParametersLength(id, productName, price, quantity);
try (FileOutputStream fos = new FileOutputStream(fileName, true)) {
fos.write(result.getBytes(StandardCharsets.UTF_8));
}
}
}
private static String setID(String path) throws IOException {
int id = 0;
try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
while (reader.ready()) {
String s = reader.readLine().substring(0, 8).trim();
int tmp = Integer.parseInt(s);
if (tmp > id) id = tmp;
}
}
return String.valueOf(id + 1);
}
private static String prepareParametersLength(
String id, String productName, String price, String quantity) {
StringJoiner joiner = new StringJoiner("");
joiner.add(" \\n ");
if (id.length() < 8) {
for (int i = 0; i < 8 - id.length(); i++) {
id = id.concat(" ");
}
} else if (id.length() > 8) id = id.substring(0, 8);
joiner.add(id);
System.out.println(id);
if (productName.length() < 30) {
for (int i = 0; i < 30 - productName.length(); i++) {
productName = productName.concat(" ");
}
} else if (productName.length() > 30) productName = productName.substring(0, 30);
joiner.add(productName);
System.out.println(productName);
if (price.length() < 8) {
for (int i = 0; i < 8 - price.length(); i++) {
price = price.concat(" ");
}
} else if (price.length() > 8) price = price.substring(0, 8);
joiner.add(price);
System.out.println(price);
if (quantity.length() < 4) {
for (int i = 0; i < 4 - quantity.length(); i++) {
quantity = quantity.concat(" ");
}
} else if (quantity.length() > 4) quantity = quantity.substring(0, 4);
joiner.add(quantity);
System.out.println(quantity);
System.out.println(joiner.toString());
return joiner.toString();
}
private static String setFileNameFromKeyboard() throws IOException {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in) {public void close() {}})) {
return reader.readLine();
}
}
}