Java I/O Programming: Exercises, Practice, Solution
Java Input-Output Exercises [18 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
1. Write a Java program to get a list of all file/directory names in the given directory.
Click me to see the solution
2. Write a Java program to get specific files with extensions from a specified folder.
Click me to see the solution
3. Write a Java program to check if a file or directory specified by pathname exists or not.
Click me to see the solution
4. Write a Java program to check if a file or directory has read and write permissions.
Click me to see the solution
5. Write a Java program to check if the given pathname is a directory or a file.
Click me to see the solution
6. 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. Write a Java program to determine the last modified date of a file.
Click me to see the solution
8. Write a Java program to read input from the Java console.
Click me to see the solution
9. Write a Java program to get the file size in bytes, KB, MB.
Click me to see the solution
10. Write a Java program to read the contents of a file into a byte array.
Click me to see the solution
11. Write a Java program to read file content line by line.
Click me to see the solution
12. Write a Java program to read a plain text file.
Click me to see the solution
13. Write a Java program to read a file line by line and store it in a variable.
Click me to see the solution
14. Write a Java program to store text file content line by line in an array.
Click me to see the solution
15. Write a Java program to write and read a plain text file.
Click me to see the solution
16. Write a Java program to append text to an existing file.
Click me to see the solution
17. Write a Java program to read the first 3 lines of a file.
Click me to see the solution
18. 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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics