में फ़ाइल से पढ़ें मैं अपने जावा प्रोग्राम में डेटा इनपुट करने के लिए एक टेक्स्ट फ़ाइल से पढ़ने की कोशिश कर रहा हूं। हालांकि, ग्रहण निरंतर मुझे एक स्रोत देता है त्रुटि नहीं मिली कोई फर्क नहीं पड़ता कि मैं फ़ाइल कहां डालता हूं।ग्रहण
मैं एक अतिरिक्त स्रोत परियोजना निर्देशिका में फ़ोल्डर बना लिया है, सवाल में फ़ाइल दोनों इसे और परियोजना के लिए बिन फाइल में है और यह अभी भी यह नहीं मिल रहा।
मैं अपने डेस्कटॉप पर इसकी एक प्रति रख दिया और वहाँ ओर इशारा करते हुए ग्रहण करने की कोशिश की, जब यह मेरे स्रोत देखने पथ के लिए ब्राउज़ करने के लिए कहा।
कोई फर्क नहीं पड़ता कि मैं क्या करता हूं यह फ़ाइल नहीं ढूंढ सकता है।
यहाँ मेरी कोड के मामले में यह उचित है:
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);
मुझे लगता है कि समस्या यह थी कि मैंने स्रोत और फाइल फ़ाइल को रीफ्रेश किया था, लेकिन प्रोजेक्ट फ़ाइल नहीं, इसलिए इसे कभी नहीं मिला। मदद के लिए धन्यवाद – Buzkie
क्या यह आपकी समस्या का समाधान करता है? –
हाँ यह अब काम करता है – Buzkie