FliQi Education App Download
प्रश्न-बैंक · Programmer Java

java.io Package — प्रश्न और उत्तर

Programmer Java · 122 जाँचे हुए (verified) प्रश्न

  • 122 जाँचे हुए प्रश्न
  • हिंदी + English

पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।

भाषा
प्रश्न 1उत्तर + हल
random access file में file pointer को किसी ख़ास स्थान पर ले जाने के लिए कौन-सी method प्रयोग होती है?
Which method is used to move the file pointer to a specific position in a random access file?
  1. AmoveTo()
  2. BjumpTo()
  3. Cseek()
  4. DmovePointer()

सही उत्तर / Answer: (C)

हल / Solution
RandomAccessFile की seek(long pos) method file pointer को file की शुरुआत से pos byte की दूरी पर रख देती है। अगला read या write वहीं से होता है। pos file की लंबाई से आगे भी हो सकता है। तब file की लंबाई तभी बढ़ती है जब वहाँ कुछ लिखा जाए। moveTo(), jumpTo() और movePointer() नाम की कोई method RandomAccessFile में नहीं है। इसलिए सही उत्तर seek() है।
The seek(long pos) method of RandomAccessFile places the file pointer pos bytes from the start of the file, and the next read or write happens there. The position may even be beyond the current end of the file; the file length grows only when something is written there. RandomAccessFile has no methods named moveTo(), jumpTo() or movePointer(). So seek(), option 3, is the correct method for moving the file pointer.
प्रश्न 2उत्तर + हल
Java में random access file operations के लिए आम तौर पर कौन-सी class प्रयोग होती है?
Which class in Java is commonly used for random access file operations?
  1. ARandomAccessFile
  2. BFileReader
  3. CBufferedWriter
  4. DFileInputStream

सही उत्तर / Answer: (A)

हल / Solution
java.io.RandomAccessFile class file के किसी भी स्थान पर पढ़ने और लिखने देती है। इसे "r" या "rw" mode में खोला जाता है। seek() से file pointer मनचाही जगह पर भेजा जाता है और getFilePointer() से उसकी स्थिति मिलती है। FileReader और FileInputStream सिर्फ़ शुरू से क्रम में पढ़ती हैं। BufferedWriter सिर्फ़ क्रम से लिखती है। इनमें seek() नहीं होता। इसलिए विकल्प 1 सही है।
The java.io.RandomAccessFile class allows reading and writing at any position in a file. It is opened in "r" or "rw" mode, seek() moves the file pointer to any position, and getFilePointer() reports the current one. FileReader and FileInputStream only read in order from the start, and BufferedWriter only writes in order; none of them offers seek(). So RandomAccessFile, option 1, is the class used for random access file operations in Java.
प्रश्न 3उत्तर + हल
random access file क्या है?
What is a random access file?
  1. Aऐसी file जिसे केवल क्रम से (sequentially) access किया जा सकता है।A file that can only be accessed sequentially.
  2. Bऐसी file जिसमें क्रमवार (sequential) और बिना क्रम (non-sequential) दोनों तरह की access हो सकती है।A file that allows for both sequential and non-sequential access.
  3. Cऐसी file जिसे केवल किसी ख़ास file format से access किया जा सकता है।A file that can only be accessed using a specific file format.
  4. Dऐसी file जिसे केवल randomly access किया जा सकता है।A file that can only be accessed randomly.

सही उत्तर / Answer: (B)

हल / Solution
random access file में एक file pointer होता है। हर read या write उसी जगह से होता है और pointer आगे बढ़ जाता है, यानी क्रम से (sequential) पढ़ना भी चलता है। seek() से pointer को किसी भी जगह पर सीधे भेजा जा सकता है, यानी बिना क्रम (non-sequential) access भी होता है। Java में RandomAccessFile class यही करती है। यह किसी ख़ास format तक सीमित नहीं है। इसलिए विकल्प 2 सही है।
A random access file keeps a file pointer. Each read or write happens at that position and then moves the pointer forward, so sequential reading still works. With seek(), the pointer can jump directly to any position, which gives non-sequential access as well. In Java, the RandomAccessFile class works this way, and it is not tied to any particular file format. So option 2, allowing both sequential and non-sequential access, is correct.
प्रश्न 4उत्तर + हल
sequential file से text की एक line पढ़ने के लिए निम्नलिखित में से कौन-सी method प्रयोग होती है?
Which of the following methods is used to read a line of text from a sequential file?
  1. AreadLine()
  2. BreadText()
  3. Cread()
  4. DreadString()

सही उत्तर / Answer: (A)

हल / Solution
sequential file से text की पूरी line पढ़ने के लिए आम तौर पर BufferedReader की readLine() method लगती है। यह line को String के रूप में लौटाती है और file ख़त्म होने पर null देती है। इसीलिए while ((line = br.readLine()) != null) वाला loop बहुत चलता है। read() सिर्फ़ एक character पढ़ती है, पूरी line नहीं। readText() और readString() नाम की कोई method Reader classes में नहीं है। इसलिए विकल्प 1 सही है।
To read a whole line of text from a sequential file, the usual choice is the readLine() method of BufferedReader. It returns the line as a String and gives null at the end of the file, which is why the loop while ((line = br.readLine()) != null) is so common. read() reads only one character, not a full line. There are no methods named readText() or readString() in the Reader classes. So option 1 is correct.
प्रश्न 5उत्तर + हल
sequential files क्या होती हैं?
What are sequential files?
  1. Aवे files जिन्हें randomly access किया जा सकता है।Files that can be accessed randomly.
  2. Bवे files जो data को क्रम से (sequential order में) रखती हैं।Files that store data in a sequential order.
  3. Cवे files जो data को बिना क्रम के रखती हैं।Files that store data in a random order.
  4. Dवे files जिन्हें Java programs access नहीं कर सकते।Files that cannot be accessed by Java programs.

सही उत्तर / Answer: (B)

हल / Solution
sequential file में records एक के बाद एक क्रम से रखे जाते हैं। उन्हें उसी क्रम में शुरू से अंत की ओर पढ़ा या लिखा जाता है। किसी बीच वाले record तक पहुँचने के लिए उससे पहले के सारे records पार करने पड़ते हैं। किसी भी जगह सीधे पहुँचना random access file की ख़ासियत है। Java ऐसी files को FileReader या BufferedReader जैसी classes से आराम से पढ़ता है। इसलिए विकल्प 2 सही है।
In a sequential file, records are stored one after another in order and are read or written in that same order from start to end. To reach a record in the middle, all records before it have to be passed over. Jumping directly to any position is the feature of a random access file, not a sequential one. Java reads such files easily with classes like FileReader or BufferedReader. So option 2 is correct.
प्रश्न 6उत्तर + हल
Java में file streams के बारे में कौन-सा कथन सही है?
Which of the following statements about file streams in Java is true?
  1. AFileInputStream text files पढ़ने के लिए प्रयोग होती है।FileInputStream is used for reading text files.
  2. BFileOutputStream file में binary data लिखने के लिए प्रयोग होती है।FileOutputStream is used for writing binary data to a file.
  3. CFileReader file में text data लिखने के लिए प्रयोग होती है।FileReader is used for writing text data to a file.
  4. DFileWriter file से binary data पढ़ने के लिए प्रयोग होती है।FileWriter is used for reading binary data from a file.

सही उत्तर / Answer: (B)

हल / Solution
FileOutputStream एक byte stream है, जो file में कच्चे bytes यानी binary data लिखती है। Java documentation के अनुसार FileInputStream कच्चे bytes, जैसे image data, पढ़ने के लिए है। text यानी characters पढ़ने के लिए FileReader सुझाई जाती है। FileReader पढ़ती है, लिखती नहीं। FileWriter text लिखती है, binary नहीं पढ़ती। इसलिए विकल्प 3 और 4 उलटे हैं, और विकल्प 2 सही है।
FileOutputStream is a byte stream that writes raw bytes, that is binary data, to a file. The Java documentation says FileInputStream is meant for reading raw bytes such as image data, and that FileReader should be used for reading characters, that is text. FileReader only reads and never writes, while FileWriter writes text and does not read binary data. So options 3 and 4 swap the roles, and option 2 is the correct statement.
प्रश्न 7उत्तर + हल
Java में File class का उद्देश्य क्या है?
What is the purpose of the File class in Java?
  1. Aयह file में binary data पढ़ने और लिखने के लिए प्रयोग होती है।It is used for reading and writing binary data to a file.
  2. Bयह directories बनाने और संभालने के लिए प्रयोग होती है।It is used for creating and managing directories.
  3. Cयह user से input पढ़ने के लिए प्रयोग होती है।It is used for reading input from the user.
  4. Dयह network communication के लिए प्रयोग होती है।It is used for network communication.

सही उत्तर / Answer: (B)

हल / Solution
File class file और directory के path को दर्शाती है और उन्हें संभालने का काम करती है। mkdir() और mkdirs() से directory बनती है, list() से उसकी सामग्री मिलती है, और delete() व renameTo() से बदलाव होते हैं। File class ख़ुद file का content न पढ़ती है, न लिखती है। उसके लिए FileInputStream और FileOutputStream जैसी stream classes हैं। input के लिए Scanner है, network के लिए java.net है। इसलिए विकल्प 2 सही है।
The File class represents file and directory pathnames and is used to manage them. mkdir() and mkdirs() create directories, list() gives their contents, and delete() and renameTo() change them. File itself never reads or writes the contents of a file; stream classes such as FileInputStream and FileOutputStream do that. User input is read with Scanner, and network work belongs to java.net. So option 2, creating and managing directories, is correct.
प्रश्न 8उत्तर + हल
Java में files और directories को दर्शाने के लिए कौन-सी class प्रयोग होती है?
Which class in Java is used to represent files and directories?
  1. AFile
  2. BPath
  3. CDirectory
  4. DStream

सही उत्तर / Answer: (A)

हल / Solution
java.io.File class किसी file या directory के path (pathname) को दर्शाती है। इसी एक class से file और directory दोनों संभाले जाते हैं। इसके लिए exists(), isDirectory(), mkdir() और list() जैसी methods हैं। Path, java.nio.file का एक interface है, class नहीं। Java में Directory नाम की अलग class नहीं है। Stream data के प्रवाह के लिए है, file को दर्शाने के लिए नहीं। इसलिए विकल्प 1 सही है।
The java.io.File class represents the pathname of a file or a directory, so one class handles both, with methods such as exists(), isDirectory(), mkdir() and list(). Path is an interface in java.nio.file, not a class. Java has no separate class named Directory. A Stream is about a flow of data, not about representing a file on disk. So File, option 1, is the class used to represent files and directories in Java.
प्रश्न 9उत्तर + हल
Java का कौन-सा package file handling के लिए classes और interfaces देता है?
Which package in Java provides classes and interfaces for file handling operations?
  1. Ajava.io
  2. Bjava.util
  3. Cjava.net
  4. Djava.nio

सही उत्तर / Answer: (A)

हल / Solution
java.io package में file handling की मुख्य classes हैं, जैसे File, FileReader, FileWriter, FileInputStream, FileOutputStream, BufferedReader और RandomAccessFile। java.util में collections, Scanner और date जैसी utility classes हैं। java.net network communication के लिए है। java.nio package में ख़ुद Buffer जैसी classes हैं। Java 7 में आई नई file API उसके sub-package java.nio.file में है। इसलिए file handling का मूल package java.io है।
The java.io package holds the main file handling classes such as File, FileReader, FileWriter, FileInputStream, FileOutputStream, BufferedReader and RandomAccessFile. java.util provides utility classes like collections, Scanner and dates, and java.net is for network communication. The java.nio package itself mainly holds buffer classes; the newer file API added in Java 7 sits in its sub-package java.nio.file. So the core package for file handling is java.io, option 1.
प्रश्न 10उत्तर + हल
Java में PrintWriter के constructor में autoFlush parameter का क्या अर्थ है?
What does the autoFlush parameter in the PrintWriter constructor signify in Java?
  1. Aयह बताता है कि data अपने आप नीचे वाले stream में flush होगा या नहीं।It specifies whether data should be automatically flushed to the underlying stream.
  2. Bयह file का encoding format बताता है।It specifies the encoding format of the file.
  3. Cयह file की permissions बताता है।It specifies the permissions of the file.
  4. Dयह बताता है कि data मौजूदा file के अंत में जोड़ा जाए या नहीं।It specifies whether data should be appended to the existing file or not.

सही उत्तर / Answer: (A)

हल / Solution
PrintWriter(OutputStream out, boolean autoFlush) जैसे constructor में autoFlush true रखने पर println(), printf() और format() के बाद buffer अपने आप flush हो जाता है। तब हर बार flush() बुलाना नहीं पड़ता। encoding के लिए Charset वाला अलग parameter है। file की permissions PrintWriter तय नहीं करता। file के अंत में जोड़ने (append) वाला boolean FileWriter और FileOutputStream के constructor में होता है। इसलिए विकल्प 1 सही है।
In constructors like PrintWriter(OutputStream out, boolean autoFlush), setting autoFlush to true makes the buffer flush automatically after println(), printf() and format(), so you do not need to call flush() each time. Encoding is set through a separate Charset parameter, and PrintWriter never sets file permissions. The boolean that controls appending to an existing file belongs to the FileWriter and FileOutputStream constructors, not PrintWriter. So option 1 is correct.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 12उत्तर app में
Java में PrintWriter की println() method के बारे में कौन-सा कथन सही है?
Which of the following statements about PrintWriter's println() method in Java is true?
  1. Aयह output stream में data का एक byte लिखती है।It writes a single byte of data to the output stream.
  2. Bयह output stream में एक character लिखती है।It writes a single character to the output stream.
  3. Cयह output stream में text की एक line लिखती है।It writes a line of text to the output stream.
  4. Doutput stream ख़ाली होने पर यह IOException फेंकती है।It throws an IOException if the output stream is empty.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 14उत्तर app में
Java में PrintWriter के constructor में दी गई file मौजूद न हो तो क्या होता है?
What happens if the file specified in the PrintWriter constructor does not exist in Java?
  1. AIOException फेंकी जाती है।An IOException is thrown
  2. BFileNotFoundException फेंकी जाती है।A FileNotFoundException is thrown.
  3. Cfile अपने आप बन जाती है।The file is created automatically.
  4. Dprogram compile हो जाता है पर runtime exception फेंकता है।The program compiles successfully but throws a runtime exception.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 15उत्तर app में
Java में PrintWriter class का उद्देश्य क्या है?
What is the purpose of the PrintWriter class in Java?
  1. Aयह user से input पढ़ने के लिए प्रयोग होती है।It is used for reading input from the user.
  2. Bयह file में binary data लिखने के लिए प्रयोग होती है।It is used for writing binary data to a file.
  3. Cयह output stream में formatted text लिखने के लिए प्रयोग होती है।It is used for writing formatted text to an output stream.
  4. Dयह network communication के लिए प्रयोग होती है।It is used for network communication.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 16उत्तर app में
Console class में format() method का उद्देश्य क्या है?
What is the purpose of the format() method in the Console class?
  1. Aयह console window को format करती है।It formats the console window.
  2. Bयह दी गई format string और arguments के अनुसार output string को format करती है।It formats the output string according to the specified format string and arguments.
  3. Cयह console से मिले input text को format करती है।It formats the input text received from the console.
  4. Dयह Console object के input stream को format करती है।It formats the input stream of the Console object.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 18उत्तर app में
Console class में readPassword() method का उद्देश्य क्या है?
What is the purpose of the readPassword() method in the Console class?
  1. Aयह user से password पढ़ती है, बिना characters को console पर दिखाए।It reads a password from the user without echoing characters to the console.
  2. Bयह console से text की एक line पढ़ती है।It reads a line of text from the console.
  3. Cयह console से एक integer पढ़ती है।It reads an integer from the console.
  4. Dयह console से binary data पढ़ती है।It reads binary data from the console.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 19उत्तर app में
जहाँ console उपलब्ध न हो, ऐसे वातावरण में System.console() से Console object लेने की कोशिश करने पर क्या होता है?
What happens if you try to retrieve the Console object using System.console() in an environment where the console is not available?
  1. Aयह null लौटाता है।It returns null.
  2. Bयह NullPointerException फेंकता है।It throws a NullPointerException.
  3. Cयह IOException फेंकता है।It throws an IOException.
  4. Dयह ConsoleUnavailableException फेंकता है।It throws a ConsoleUnavailableException.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 21उत्तर app में
Java में Console object का reference कैसे प्राप्त किया जाता है?
How can you obtain a reference to the Console object in Java?
  1. Anew keyword से object बनाकर।By instantiating it with the new keyword.
  2. Bstatic method System.console() को बुलाकर।By calling the static method System.console().
  3. Cjava.io package से import करके।By importing it from the java.io package.
  4. DScanner object बनाकर उसे Console object में बदलकर।By creating a Scanner object and converting it to a Console object.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 22उत्तर app में
Java में Console class का उद्देश्य क्या है?
What is the purpose of the Console class in Java?
  1. Aयह file में binary data पढ़ने और लिखने के लिए प्रयोग होती है।It is used for reading and writing binary data to a file.
  2. Bयह user से input पढ़ने और output stream में text data लिखने के लिए प्रयोग होती है।It is used for reading input from the user and writing text data to an output stream.
  3. Cयह network communication के लिए प्रयोग होती है।It is used for network communication.
  4. Dयह directories बनाने और संभालने के लिए प्रयोग होती है।It is used for creating and managing directories.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 24उत्तर app में
Java में Scanner class का प्रयोग करते समय input की ग़लती को संभालने के लिए कौन-सी class प्रयोग होती है?
Which class is used to handle input errors when using the Scanner class in Java?
  1. AInputHandler
  2. BIOException
  3. CScannerException
  4. DInputMismatchException
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 26उत्तर app में
Scanner class में useDelimiter() method का उद्देश्य क्या है?
What is the purpose of the useDelimiter() method in the Scanner class?
  1. Aयह tokens को अलग करने वाला character तय करती है।It sets the character used to separate tokens.
  2. Bयह input समाप्त करने वाला character तय करती है।It sets the character used to terminate input.
  3. Cयह file के अंत को दर्शाने वाला character तय करती है।It sets the character used to indicate the end of file.
  4. Dयह file की शुरुआत को दर्शाने वाला character तय करती है।It sets the character used to indicate the beginning of file.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 27उत्तर app में
Java में Scanner की next() method के बारे में कौन-सा कथन सही है?
Which of the following statements about Scanner's next() method in Java is true?
  1. Aयह input stream से data का एक byte पढ़ती है।It reads a single byte of data from the input stream.
  2. Bयह input stream से एक character पढ़ती है।It reads a single character from the input stream.
  3. Cयह input stream से एक token पढ़ती है।It reads a single token from the input stream.
  4. Dinput stream ख़ाली होने पर यह IOException फेंकती है।It throws an IOException if the input stream is empty.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 29उत्तर app में
Java में Scanner बंद (close) करने के बाद उससे input पढ़ने की कोशिश की जाए तो क्या होता है?
What happens if the Scanner is closed and an attempt is made to read input from it in Java?
  1. Aयह FileNotFoundException फेंकता है।It throws a FileNotFoundException.
  2. Bयह NullPointerException फेंकता है।It throws a NullPointerException.
  3. Cयह IllegalStateException फेंकता है।It throws an IllegalStateException.
  4. Dयह IOException फेंकता है।It throws an IOException.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 30उत्तर app में
Java में Scanner में पढ़ने के लिए अगला token उपलब्ध है या नहीं, यह जाँचने के लिए कौन-सी method प्रयोग होती है?
Which method is used to check if the Scanner has another token available for reading in Java?
  1. AhasNextLine()
  2. BhasNext()
  3. ChasNextInt()
  4. DhasToken()
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
java.io Package के सभी 122 प्रश्न — उत्तर, हल और अभ्यास

FliQi Question Bank app में topic-वार अभ्यास, कठिनाई-स्तर और आपकी प्रगति।

  • पहला test मुफ़्त
  • हिंदी + English
  • जाँचे हुए उत्तर और हल

यह topic किन परीक्षाओं में आता है

Programmer Java के दूसरे topics

सभी topics