Java fileinputstream No such file or directory -


i'm trying learn how use read line line text file. though put txt file in same src, console shows error - no such file or directory.

public class ddd {  public static void main(string[] args) {     fileinputstream fis = null;     bufferedreader reader = null;     try {         fis = new fileinputstream("/dd/src/com/dd/input.txt");         reader = new bufferedreader(new inputstreamreader(fis));         system.out                 .println("reading file line line using bufferedreader");         string line = reader.readline();         while (line != null) {             system.out.println(line);             line = reader.readline();         }     } catch (exception e) {         system.out.println(e.getmessage());     } {         try {             reader.close();             fis.close();         } catch (ioexception e) {             system.out.println(e.getmessage());         }      } } 

}enter image description here

the problem here:

"/dd/src/com/dd/input.txt" 

on linux @ least, absolute path. want instead path relative project root:

"src/com/dd/input.txt" 

or, if you're packaging file program, use resource stream instead of raw fileinputstream:

inputstream = ddd.class.getresourceasstream("input.txt"); 

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -