JAVA ASSIGNMENT1
JAVA ASSIGNMENT1
Roll no-2200290530015
Sec- A
JAVA ASSIGNMENT-01
1). WAP to create a method that reads a file and throws an exception
if the file import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException;
try {
String line;
System.out.println("File content:");
System.out.println(line);
} finally { if
(reader != null) {
try {
reader.close();
} catch (IOException e) {
throw new Exception("An error occurred while closing the file: " + e.getMessage());
}
Name-Ankit
Roll no-2200290530015
Sec- A
try {
readFile(filePath);
} catch (Exception e) {
System.err.println(e.getMessage());
import java.util.Scanner;
Roll no-2200290530015
Sec- A
if (scanner.hasNextInt()) { array[i] =
scanner.nextInt();
} else {
System.out.println("Array elements:");
scanner.close();