greg zakharov, без паники
код мой такой
Код:
public static String[] parsinganytextfile(String line) {
ArrayList<String> result = new ArrayList<String>();
Pattern pattern = Pattern.compile("^(.*)(.*[r|-][w|-][x|-][r|-][w|-][x|-][r|-][w|-][x|-])(.*)$");
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
for (int i = 1; i <= matcher.groupCount(); ++i) {
result.add(matcher.group(i));
}
}
return result.toArray(new String[0]);
}
public static void RecalcRules() {
String InputTextFile;
JFileChooser fileopen = new JFileChooser();
int ret = fileopen.showDialog(null, "Открыть файл");
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fileopen.getSelectedFile();
InputTextFile = file.getAbsolutePath();
} else {
return;
}
String OutTextFile = InputTextFile + "_new";
//погнали
String[][] TextMass = new String[0][];
try {
TextMass = Files.lines(Paths.get(InputTextFile))
.map(g -> parsinganytextfile(g))
.toArray(String[][]::new);
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < TextMass.length; i++) {
if (TextMass[0].length == 1) {
Functions.writefile(OutTextFile, getDigits(TextMass[i][0].replace("s", "x")));
}
if (TextMass[0].length == 2) {
Functions.writefile(OutTextFile, getDigits(TextMass[i][0].replace("s", "x")) + " " + TextMass[i][1]);
} else {
Functions.writefile(OutTextFile, TextMass[i][0] + " " + getDigits(TextMass[i][1].replace("s", "x")) + " " + TextMass[i][2]);
}
}
}
public static String getDigits(String s) {
if (!s.matches("^.*([r|-][w|-][x|-]){3}$")) {
throw new IllegalArgumentException("Achtung!");
}
Function<String, String> rwxMapper = rwx -> String.valueOf(Integer.parseInt(rwx.replaceAll("[rwx]", "1").replaceAll("-", "0"), 2));
return Arrays.stream(s.substring(s.length() - 9).split("(?<=\\G...)")).map(rwxMapper).collect(joining());
}
Что делает: читает файл в двумерный массив, выодит из массива в новый файл заменяя уже пересчитыными значениями
Iska, бинго
Но не факт что это тот способ верный.