I want to read some data for my app. Here my code:
URL url = Myclass.class.getResource("/data/file.txt"); //Myclass is my class name
File file = new File(url.toString()); //maybe I met error here.
//File Constructor just receive String object, I don't know how to convert
FileInputStream reader = new FileIputStream(file);
I don’t know how to change url to File to read it. Please tell me how to solve.
Thanks 🙂
You can’t read a resource as if it were a file. The following syntax should work:
To avoid relative / absolute path issues, you can also use: