Java Practice Exercise – File Handling

File handling
 

  • Read from console and write to file.
  • Read from file and display in console.
  • Write a Java program that reads a file name from the user, displays information about whether the file exists, whether the file is readable, or writable, the type of file and the length of the file in bytes.
  • Write a program that copies the content of one file to another by removing unnecessary space between words.
  • Write a Java program ‘LineCounts.java’ that will count the number of lines in each files that is specified on the command line. Note that multiple files can be specified, as in
“java LineCounts file1.txt file2.txt file3.txt”.
  • Write a Java program to read from an input file and convert the words to lower case and write it in another file.
  • Write a Java program that reads a file and displays a file and displays the file on the screen, with a line number before each line.
  • Write a Java program that displays the number of characters, lines and words in a text file.
  • Copy file.
  • Merge two files.
  • Search if a word exists in a file. Count and display the number of times the word occurs in the file. Display all lines in which the word exists.
  • Delete a word in a file.
  • Replace a word in a file.
  • Write a program to compare two files, printing the first line where they differ.
  • Display file content with line number.
  • Display nth line of a file.
  • Display from nth line to mth line of a file.
  • Copy first 10 lines.