Answer to Question #259586 in Java | JSP | JSF for Shadow

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.


1
Expert's answer
2021-11-01T03:02:31-0400


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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS