0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class FileRead
{


public static void main (String[] args) throws IOException
{   

    try
    {
        FileInputStream fstream = new FileInputStream("data.txt");
        BufferedReader br = new BufferedReader(new InputStreamReader(fstream));

        String strLine;     
        while ((strLine = br.readLine()) != null) 
        {

          System.out.println (strLine);
        }   
        br.close();
    }
    catch (IOException e) 
    {
        e.printStackTrace(); 
    }

}

I put the data.txt in the same location as the java project. I have to get this done for a research project for my java class.

Noah Davison
  • 1
  • 1
  • 1

2 Answers2

0

Use src/data.txt to find a file in the same place as your project :)

Means that it is the same location as your source folder (put it inside src)

EDToaster
  • 3,160
  • 3
  • 16
  • 25
0

you forgot ./ thats why it says not found file

OPK
  • 4,120
  • 6
  • 36
  • 66