Fionageo80
asked on
read file with relative path of file inside of a project
Hi I have to read a file that is in my project, I have to read it line by line.
How can I get the relative path?
Thanks
How can I get the relative path?
Thanks
BufferedReader d = null;
try {
d = new BufferedReader(new FileReader ("D:\\Users\\project\\test\\src\\queries\\sql.txt"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String line;
System.getProperty("user.d ir")
new File(".").getAbsolutePath( );
If its within the project
Put your file in the classpath of your project and use the getClass().getResourceAsSt ream.
If file is outside your project( ie., written by someone else and your reading it)
Have a properties file in your class path which can have the path of the file where your file would be. read the properties file, get the file path from it and read the file.
Put your file in the classpath of your project and use the getClass().getResourceAsSt
If file is outside your project( ie., written by someone else and your reading it)
Have a properties file in your class path which can have the path of the file where your file would be. read the properties file, get the file path from it and read the file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window