Question #259586

Write a Java program to create a text file named ‘File1.txt.’ Write your Index Number and batch

name in two separate lines in the above file. Read the file and display the content of the text file.


Expert's answer



import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;


public class App {


	public static void main(String[] args) {
		try {
			// the file to be opened for reading
			FileInputStream fis = new FileInputStream("File1.txt");
			Scanner sc = new Scanner(fis);
			System.out.println("Index Number is: "+sc.nextLine());
			System.out.println("Batch name  is: "+sc.nextLine());
			sc.close(); // closes the scanner
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS