C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » Java programs

Java file handling programs - File Input Output Examples

This section contains solved programs with output and explanation of file handling in Java like creating file, writing data in file, reading data from file, copying file, removing file etc.

File handling programs in java

  1. Java program to read a file line by line.
    In this java program, we are going to learn how to read a file line by line and print the line on the output screen? Here, we are reading content of a file line by line and printing.
  2. Java program to read content from one file and write it into another file.
    In this java program, we are going to learn how to read content from one file and write it into another file?
  3. Java program to get file creation, last access and last modification time.
    In this java program, we are going to learn how to access file’s last access time, creation time and last modified time using BasicFileAttributes class.
  4. Java program to get the file’s owner name.
    In this java program, we are going to learn how to get the file’s owner name? Method getOwner() of class FileOwnerAttributeView is used to get the owner name.
  5. Java program to get the basic file attributes (specific to DOS).
    In this java program, we are going to learn how to get DOS based basic attributes like file’s hidden, read-only property etc?
  6. Java program to get the attributes of a file.
    In this java program, we are going to learn how to get and print the attributes of a file? Here, we are accessing the attributes like file creation time, last access time, last modified time, file key etc.
  7. Java program to read and print all files from a zip file.
    In this java program, we are going to learn how to read a zip file and access all files from it? Here, we will have a zip file, read files from it and print file names.
  8. Java program to check whether a file can be read or not.
    In this java program, we are going to check whether a given file can be read or not? To check this, we are using File.canRead() method.
  9. Java program to create directory/folder in particular drive.
    In this Java program, we will learn how we can create a directory or a folder? To create a directory, we use File.mkdir() method in Java.
  10. Java program to get the size of given file in bytes, kilobytes and megabytes.
    In this Java program, we are going to learn how to get the size of a given file in bytes, kilobytes and megabytes?
  11. Java program to check whether a file is hidden or not.
    In this java program, we are going to learn, how to check whether a file is hidden or not? Method isHidden() of File class is used to check it.
  12. Java program to read text from file from a specified index or skipping byte using FileInputStream.
    In this program, we are going to learn how to read text from a file after skipping some bytes and print them on the output screen using FileInputStream.
  13. Java program to determine number of bytes written to file using DataOutputStream.
    In this java program, we are going to learn how to get (determine) the number of bytes written to a file using DataOutputStream? Here, we will write text in file and print the number of written bytes.
  14. Java program to append text/string in a file.
    In this java program, we are going to learn how to append text/string in a given file? Here, we have a file with some pre written content and we are appending text in it.
  15. Java program to get the last modification date and time of a file.
    In this java program, we will learn how to get the file’s last modification date and time? Here, we will give a file name and program will print its last modification date and time.
  16. Java - Copy Content of One File to Another File using Java Program. (Code Snippet)
  17. Java - Print File Content, Display File using Java Program. (Code Snippet)
  18. Java program to copy files.
  19. Java program to delete a file.
  20. Java program to get file size and file path.
  21. Java program to read content from file using BufferedReader.
  22. Java program to write content into file using BufferedWriter.
  23. Java program to read content from file using FileInputStream.
  24. Java program to write content into file using FileOutputStream.
  25. Java program to create a new file.




Sponsored Links




COMMENTS