public class CLIENT_PATH { String PATH; Path Path; public void INPUT_PATH(){ out.println("Введите путь"); do { out.print(" "); Scanner in = new Scanner(System.in); PATH = in.next(); Path = Paths.get(PATH); if (Files.exists(Path)) { out.println(" Путь введён\n"); } else out.println(" Ошибка"); } while(Files.notExists(Path)); out.println(PATH); } } 

Why when entering Russian characters K (R), P (G), O (J), and M (V) and possibly others throws an exception and writes in the answer that completely different characters are entered?

Enter the path

P

Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <? > at index 0:?

Enter the path

m

Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <<> at index 0: <

  • Try to specify the encoding. - pavel
  • @Pavel The NetBeans project is UTF-8, I have not changed the encoding anywhere. - aaa
  • And in Windows terminals win1251 or in general 861 - pavel
  • @pavel Where can I change the encoding then? - aaa

1 answer 1

  do { try { out.print("\n "); Scanner in = new Scanner(System.in); PA = in.next(); Path PATH = Paths.get(PA); if(Files.exists(PATH)) { out.print("\n Adres programm vvedon\n"); } else { PA = null; out.print("\n Oshibka\n"); } } catch (InvalidPathException E) { PA = null; out.print(" Oshibka\n"); } } while(PA == null);