File Related Java Code

Hello Everyone,  I am a new learner in java. I have been trying to learn file related java problems but I can't seem to run the basic file related codes in my eclipse client. I tried the online compiler as well but no luck. I am getting errors like "The filename, directory name, or volume label syntax is incorrect" "cannot find symbol" " File not found" . My jdk and everything is up to date. Can anyone point out what am I doing wrong ?

This is the code I have been trying to run on interviewbit. for the input files 1 2 3 4 .

package QuestionA;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import java.util.Scanner;


public class NewClass1 {
     public static void main(String[] args) {
            try {
              File myObj = new File("input.txt");
              Scanner myReader = new Scanner(myObj);
              while (myReader.hasNextLine()) {
                String data = myReader.nextLine();
                System.out.println(data);
              }
              myReader.close();
            } catch (FileNotFoundException e) {
              System.out.println("An error occurred.");
              e.printStackTrace();
            }
          }
    }

This is my first time posting. I apologize if I posted this in wrong way.
avatar shivambhatele
@shivambhatele

1 Kontribusi 0 Poin

Dipost 2 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban