Top Java I/O Interview Questions | JavaInUse

Top Java I/O Interview Questions.

In this post we will look at Java I/O interview questions. Examples are provided with explanation.

Q: What is Java I/O ?
Java I/O (Input and Output) is used to process the input and produce the output. Java makes use of the stream concepts to make I/O operation fast. The package contains all the classes required for input and output operations.

Q: What is difference between Scanner and BufferedReader?
Scanner is used for parsing tokens from the contents of the stream while BufferedReader just reads the stream and does not do any special parsing. Usually we pass a BufferedReader to a scanner as the source of characters to parse.

Q: How to process object and produce a String?
static String convertStreamToString( iStream)
    java.util.Scanner scanInput = new java.util.Scanner(iStream).useDelimiter("\\A");
    return scanInput.hasNext() ? : "";

Q: How to create a Java String from the contents of a file??
static String readFile(String path, Charset encoding) 
  throws IOException 
  byte[] encoded = Files.readAllBytes(Paths.get(path));
  return new String(encoded, encoding);
Q: What are the uses of FileInputStream and FileOutputStream in java?
A: and were introduced in JDK 1.0. These APIs are used to read and write stream input and output. They can also be used to read and write images.

See Also

Spring Boot Interview Questions Apache Camel Interview Questions Drools Interview Questions Enterprise Service Bus- ESB Interview Questions. JBoss Fuse Interview Questions Top ElasticSearch frequently asked interview questions Angular 2 Interview Questions