Java I/O Programming: Exercises, Practice, Solution
This resource offers a total of 90 Java Input-Output problems for practice. It includes 18 main exercises, each accompanied by solutions, detailed explanations, and four related problems.
[An Editor is available at the bottom of the page to write and execute the scripts.]
1. List Files in Directory
Write a Java program to get a list of all file/directory names in the given directory.
Click me to see the solution
2. Get Files by Extension
Write a Java program to get specific files with extensions from a specified folder.
Click me to see the solution
3. Check Path Exists
Write a Java program to check if a file or directory specified by pathname exists or not.
Click me to see the solution
4. Check Read and Write Permissions
Write a Java program to check if a file or directory has read and write permissions.
Click me to see the solution
5. Check File or Directory
Write a Java program to check if the given pathname is a directory or a file.
Click me to see the solution
6. Compare Files Lexicographically
Write a Java program to compare two files lexicographically.
According to Wikipedia:
In mathematics, the lexicographic or lexicographical order (also known as lexical order, dictionary order, alphabetical order or lexicographic(al) product) is a generalization of the way the alphabetical order of words is based on the alphabetical order of their component letters. This generalization consists primarily in defining a total order over the sequences (often called words in computer science) of elements of a finite totally ordered set, often called alphabet.
Click me to see the solution
7. Get File Last Modified Date
Write a Java program to determine the last modified date of a file.
Click me to see the solution
8. Read Console Input
Write a Java program to read input from the Java console.
Click me to see the solution
9. Get File Size
Write a Java program to get the file size in bytes, KB, MB.
Click me to see the solution
10. Read File into Byte Array
Write a Java program to read the contents of a file into a byte array.
Click me to see the solution
11. Read File Line by Line
Write a Java program to read file content line by line.
Click me to see the solution
12. Read Plain Text File
Write a Java program to read a plain text file.
Click me to see the solution
13. Store File Lines in Variable
Write a Java program to read a file line by line and store it in a variable.
Click me to see the solution
14. Store File Lines in Array
Write a Java program to store text file content line by line in an array.
Click me to see the solution
15. Write and Read Text File
Write a Java program to write and read a plain text file.
Click me to see the solution
16. Append Text to File
Write a Java program to append text to an existing file.
Click me to see the solution
17. Read First 3 Lines of File
Write a Java program to read the first 3 lines of a file.
Click me to see the solution
18. Find Longest Word in File
Write a Java program to find the longest word in a text file.
Click me to see the solution
Java Code Editor
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.