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 ?
A: 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 java.io package contains all the classes required for input and output operations.
Q: What is difference between Scanner and BufferedReader?
A: 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 java.io.InputStream object and produce a String?
A:
Q: How to create a Java String from the contents of a file??
A:
A: java.io.FileInputStream and java.io.FileOutputStream 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.
Q: What is Java I/O ?
A: 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 java.io package contains all the classes required for input and output operations.
Q: What is difference between Scanner and BufferedReader?
A: 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 java.io.InputStream object and produce a String?
A:
static String convertStreamToString(java.io.InputStream iStream)
{
java.util.Scanner scanInput = new java.util.Scanner(iStream).useDelimiter("\\A");
return scanInput.hasNext() ? scanInput.next() : "";
}
Q: How to create a Java String from the contents of a file??
A:
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: java.io.FileInputStream and java.io.FileOutputStream 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
Popular Posts
1Z0-830 Java SE 21 Developer Certification
1Z0-819 Java SE 11 Developer Certification
1Z0-829 Java SE 17 Developer Certification
AWS AI Practitioner Certification
AZ-204 Azure Developer Associate Certification
AZ-305 Azure Solutions Architect Expert Certification
AZ-400 Azure DevOps Engineer Expert Certification
DP-100 Azure Data Scientist Associate Certification
AZ-900 Azure Fundamentals Certification
PL-300 Power BI Data Analyst Certification
Spring Professional Certification
Azure AI Foundry Hello World
Azure AI Agent Hello World
Foundry vs Hub Projects
Build Agents with SDK
Bing Web Search Agent
Function Calling Agent
Spring Boot + Azure Key Vault Hello World Example
Spring Boot + Elasticsearch + Azure Key Vault Example
Spring Boot Azure AD (Entra ID) OAuth 2.0 Authentication
Deploy Spring Boot App to Azure App Service
Secure Azure App Service using Azure API Management
Deploy Spring Boot JAR to Azure App Service
Deploy Spring Boot + MySQL to Azure App Service
Spring Boot + Azure Managed Identity Example
Secure Spring Boot Azure Web App with Managed Identity + App Registration
Elasticsearch 8 Security - Integrate Azure AD OIDC