w3resource

Java I/O Programming: Exercises, Practice, Solution

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 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.



Java: Tips of the Day

Float vs double

Programmers often cannot select the precision they need for floating-point numbers. Float requires only 4 bytes, but it has only 7 significant digits, while Double is twice as accurate (15 digits), but twice as wasteful.

In fact, most processors are able to work with Float and Double equally effectively, so use the recommendation of Bjorn Stroustrup:

"Choosing the right accuracy in real-world problems requires a good understanding of the nature of machine computing. If you do not have it, either consult with someone, or study the problem yourself, or use double and hope for the best."

Ref: https://bit.ly/3y3CjL9