Я пытаюсь прочитать текстовый файл для ввода данных в мою программу Java. Однако eclipse постоянно выдает ошибку «Источник не найден» независимо от того, куда я поместил файл.
Я создал дополнительную папку с источниками в каталоге проекта, файл, о котором идет речь, находится как в нем, так и в файле bin для проекта, и он все еще не может его найти.
Я даже поместил его копию на свой рабочий стол и попытался указать там eclipse, когда он попросил меня просмотреть путь поиска источника.
Что бы я ни делал, он не может найти файл.
вот мой код, если это уместно:
System.out.println(System.getProperty("user.dir"));
File file = new File("file.txt");
Scanner scanner = new Scanner(file);
кроме того, он говорит, что каталог пользователя является каталогом проекта, и там тоже есть копия.
Я понятия не имею, что делать.
Спасибо, Алекс
после попытки выполнить приведенное ниже предложение и снова обновить, меня встретило множество ошибок.
FileNotFoundException(Throwable).<init>(String) line: 195
FileNotFoundException(Exception).<init>(String) line: not available
FileNotFoundException(IOException).<init>(String) line: not available
FileNotFoundException.<init>(String) line: not available
URLClassPath$JarLoader.getJarFile(URL) line: not available
URLClassPath$JarLoader.access$600(URLClassPath$JarLoader, URL) line: not available
URLClassPath$JarLoader$1.run() line: not available
AccessController.doPrivileged(PrivilegedExceptionAction<T>) line: not available [native method]
URLClassPath$JarLoader.ensureOpen() line: not available
URLClassPath$JarLoader.<init>(URL, URLStreamHandler, HashMap) line: not available
URLClassPath$3.run() line: not available
AccessController.doPrivileged(PrivilegedExceptionAction<T>) line: not available [native method]
URLClassPath.getLoader(URL) line: not available
URLClassPath.getLoader(int) line: not available
URLClassPath.access$000(URLClassPath, int) line: not available
URLClassPath$2.next() line: not available
URLClassPath$2.hasMoreElements() line: not available
ClassLoader$2.hasMoreElements() line: not available
CompoundEnumeration<E>.next() line: not available
CompoundEnumeration<E>.hasMoreElements() line: not available
ServiceLoader$LazyIterator.hasNext() line: not available
ServiceLoader$1.hasNext() line: not available
LocaleServiceProviderPool$1.run() line: not available
AccessController.doPrivileged(PrivilegedExceptionAction<T>) line: not available [native method]
LocaleServiceProviderPool.<init>(Class<LocaleServiceProvider>) line: not available
LocaleServiceProviderPool.getPool(Class<LocaleServiceProvider>) line: not available
NumberFormat.getInstance(Locale, int) line: not available
NumberFormat.getNumberInstance(Locale) line: not available
Scanner.useLocale(Locale) line: not available
Scanner.<init>(Readable, Pattern) line: not available
Scanner.<init>(ReadableByteChannel) line: not available
Scanner.<init>(File) line: not available
используемый код:
System.out.println(System.getProperty("user.dir"));
File file = new File(System.getProperty("user.dir") + "/file.txt");
Scanner scanner = new Scanner(file);