I am trying to read 3 lines from a .txt file and then write those lines to another created .txt file. The problem I have is that the compiler doesn't find my file. I have the .java and .class and the .txt file in the same exact location (a folder in my desktop). What am I doing wrong? Here's what I have started:
import java.io.*; public class FileCopyDemo0 { public static void main(String args[]) throws IOException { File file = new File("ppp.txt"); FileReader fr = new FileReader("ppp.txt"); BufferedReader br = null; br = new BufferedReader(fr); String s; while((s = br.readLine()) != null) { System.out.println("line read was: " + s); } fr.close(); } }
Also, why would I be getting a nullPointerException at the br = new BufferedReader(fr); line?