Я пытаюсь читать из текстового файла для ввода данных в свою программу java. Тем не менее, eclipse постоянно дает мне ошибку Source not found, независимо от того, где я помещаю файл.
Я сделал дополнительную папку с источниками в каталоге проекта, файл находится в файле как в файле bin, так и в файле bin, и он все еще не может его найти.
Я даже скопировал его на свой рабочий стол и попробовал указать затмение там, когда он попросил меня просмотреть исходный путь поиска.
Независимо от того, что я делаю, он не может найти файл.
здесь мой код в случае, если это уместно:
System.out.println(System.getProperty("user.dir"));
File file = new File("file.txt");
Scanner scanner = new Scanner(file);
Кроме того, он говорит, что каталог пользователя является каталогом проекта, и там есть копия.
Я не знаю, что делать.
Спасибо, Alex
после попытки повторного предложения и обновления снова меня встретили множество ошибок.
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);