0

Java code:

 String fileName = "settings.txt";

 String text = "AdresProgramm =";
 String delimiter = ";";

 Optional<String> result =
 Files
     .lines(Paths.get(fileName))
     .filter(e -> e.contains(text))
     .map(e -> {
         int start = e.indexOf(text);
         int end = e.indexOf(delimiter, start + text.length());

             return e.substring(start, end);
     })
     .findFirst();

 result.ifPresent(System.out::println);

File contents: AdresProgramm =D:\\ЭСЧФ\;

java.nio.charset.MalformedInputException: Input length = 1

Qwerty
  • 21
  • 1
  • 7
  • It seems that it's an encoding problem http://stackoverflow.com/questions/30609062/java-nio-charset-malformedinputexception-input-length-1 – RubioRic Mar 27 '17 at 07:24

3 Answers3

0

This looks like an encoding issue because of the cyrillic alphabet you are using.

Think the ISO-8859-1 encoding works for European characters apparently. Not sure if UTF-8 will work.

Have you looked at this page?

Community
  • 1
  • 1
0
Files.
lines(Paths.get(fileName), Charset.forName("windows-1251"))
aaa
  • 121
  • 1
  • 6
0

This is not an answer but may be useful to others facing this issue while coding to read mainframe files.

Use this like below:

List<String> allLines = Files.readAllLines(path,StandardCharsets.ISO_8859_1);

IBM calls it code page 819 or CP819. This is a life saver if you are processing Extended Binary format files sourced from Mainframe systems.

brijesh
  • 760
  • 6
  • 4