belongs to collection: Java File Handling Programs
// Java - Print File Content, Display File import java.io.*; public class PrintFile { public static void main(String args[]) throws IOException { File fileName = new File("d:/sample.txt"); FileInputStream inFile = new FileInputStream("d:/sample.txt"); int fileLength = (int) fileName.length(); byte Bytes[] = new byte[fileLength]; System.out.println("File size is: " + inFile.read(Bytes)); String file1 = new String(Bytes); System.out.println("File content is:\n" + file1); //close file inFile.close(); } }
Output:
File size is: 22 File content is: This is a sample file.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Print/Display File Content
Output: