0

Hi I was reading files using FileReader and Buffereader only and it was working perfectly

fr = new FileReader("C:\\Users\\User\\Documents\\Bus_Station\\Bus station\\tripFile");          
br = new BufferedReader(fr);

But I want to read put these files in somewhere so I put them in Referecnced Libraries so I can read from them on any machine without path but it is not working :/

(File file = new File("tripFile.txt");
file.createNewFile();
fr = new FileReader(file););

Any help ?

khelwood
  • 55,782
  • 14
  • 81
  • 108

1 Answers1

2

You should use resources.

  URL fileURL = Resources.getResource("test.txt");
  String text = Resources.toString(fileURL, Charsets.UTF_8);

How to add a resources folder

How do I add a resources folder to my Java project in Eclipse

adding resources in intellij for java project

How to create resource folder in Netbeans?

mesutpiskin
  • 1,771
  • 2
  • 26
  • 30
  • rather intellij and netbeans you could provide project tree structure in eclipse and how to jar it – vels4j Mar 26 '18 at 08:24
  • Use to maven resources tag , example https://stackoverflow.com/questions/17548997/maven-include-resources-into-jar – mesutpiskin Mar 26 '18 at 08:27