Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what will be output of the code error is coming please help

+1 vote
asked Jun 6, 2021 by JAHANVI GIRIYA_042 (230 points)

import java.util.Scanner;

import java.io.*;

public class FileInput

{

public static void main (String[] args) throws

IOException

{

String line;

Scanner fileScan;

File myFile = new File("sample.txt");

fileScan = new Scanner (myFile);

while (fileScan.hasNext())

{

line = fileScan.nextLine();

System.out.println (line.toUpperCase());

}

}

}

1 Answer

+1 vote
answered Jun 8, 2021 by xDELLx (10,500 points)

is the above code present in FileInput.java ?? If no , rename file to FileInput.java.

Does the current directory have "sample.txt ?? if no , create one .

Below is what i did & worked for me .

file name Main.java:


import java.util.Scanner;

import java.io.*;

public class Main

{

public static void main (String[] args) throws

IOException

{

String line;

Scanner fileScan;

File myFile = new File("Main.java");

fileScan = new Scanner (myFile);

while (fileScan.hasNext())

{

line = fileScan.nextLine();

System.out.println (line.toUpperCase());

}

}

}


Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...