w3resource logo


Java Programming Exercises

Java I/O Programming : Exercises, Practice, Solution

Secondary Nav

Java Input-Output Exercises [18 exercises with solution]

1. Write a Java program to get a list of all file/directory names from the given. Go to the editor
Click me to see the solution

2. Write a Java program to get specific files by extensions from a specified folder. Go to the editor
Click me to see the solution

3. Write a Java program to check if a file or directory specified by pathname exists or not. Go to the editor
Click me to see the solution

4. Write a Java program to check if a file or directory has read and write permission. Go to the editor
Click me to see the solution

5. Write a Java program to check if given pathname is a directory or a file. Go to the editor
Click me to see the solution

6. Write a Java program to compare two files lexicographically. Go to the editor
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 get last modified time of a file. Go to the editor
Click me to see the solution

8. Write Java program to read input from java console. Go to the editor
Click me to see the solution

9. Write a Java program to get file size in bytes, kb, mb. Go to the editor
Click me to see the solution

10. Write a Java program to read contents from a file into byte array. Go to the editor
Click me to see the solution

11. Write a Java program to read a file content line by line. Go to the editor
Click me to see the solution

12. Write a Java program to read a plain text file. Go to the editor
Click me to see the solution

13. Write a java program to read a file line by line and store it into a variable. Go to the editor
Click me to see the solution

14. Write a Java program to store text file content line by line into an array. Go to the editor
Click me to see the solution

15. Write a Java program to write and read a plain text file. Go to the editor
Click me to see the solution

16. Write a Java program to append text to an existing file. Go to the editor
Click me to see the solution

17. Write a Java program to read first 3 lines from a file. Go to the editor
Click me to see the solution

18. Write a Java program to find the longest word in a text file. Go to the editor
Click me to see the solution

 

Java Practice online





List of Exercises with Solutions :



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program