java read file from relative path in project and .jar -
i tried that:
public class filepath { public file return_path () { url url = getclass().getresource("file.txt"); file file = new file(url.getpath()); return file; } }
if print it, output path this: "/media/dates/%20uni%c3%a0/java/project%20java%20201/searchinfiles/build/classes/searchinfiles/hello.txt"
i have created method in order not redefine everytime path of file .jar have read.
there problem strange characters?
btw when call main class:
public static void main(string[] args) { filepath path = new filepath(); file file = path.return_path(); system.out.println (file); try{ bufferedreader input = new bufferedreader(new filereader(file)); string line; int = 0; while ((line = input.readline ()) != null) { system.out.println(line); } input.close(); } catch(exception ex){ system.err.println("error: " + ex.getmessage()); } }
i have "file not existing" error.
how can solve it? thanks
your urls escaped, useful webbrowsers can't write spaces in urls example , represented "%20", or hex 20, or char 32 in ascii.
what want unescape this, following post may you
Comments
Post a Comment