0

Why it gives an NoSuchFileException error when accounting for the correct path set to Eclipse?.

Exception

This is the class Part1 used for testing and failing:

public class Part1 {
    private static String input = Part1
            .readFile("C:\\Users\\Влад\\eclipse-workspace\\Practice3\\src\\ua\\nure\\budiakov\\practice3\\part1.txt");
    private static final String ENCODING = "UTF-8";

    public static String readFile(String path) {
        String res = null;
        try {
            byte[] bytes = Files.readAllBytes(Paths.get(path));
            res = new String(bytes, ENCODING);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return res;
    }

    public static String convert1(String input) {
        String[] text = input.split(System.lineSeparator());
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < text.length; i++) {
            String[] a = text[i].split(";");
            sb.append(a[0] + ": " + a[a.length - 1] + System.lineSeparator());
        }
        return sb.toString();
    }

    public static void main(String[] args) throws IOException {
        System.out.println(Part1.convert1(input) + System.lineSeparator());
    }

}
Villat
  • 1,455
  • 1
  • 16
  • 33
Moon-flow
  • 1
  • 1
  • I have made a quick and dirty test, which works OK `try { byte[] bytes = Files.readAllBytes(Paths.get("c:/temp/テスト/テスト.txt")); } catch (IOException ex) { ex.printStackTrace(); }` - so maybe your file does not exist? – Scary Wombat Oct 16 '19 at 00:48
  • 1
    `NoSuchFileException` seems very self-explanatory to me, i.e. there is no file by that full name. But, the `Влад` characters are wrong in the error message, so maybe you forgot to give the correct character set when you compiled your Java source code? – Andreas Oct 16 '19 at 00:59

0 Answers0