I am making a Java program and want to open a text(notepad) file ,that i have saved in src folder in my Java Program, I have tried to do it by the following code , but it is giving error. “The method exec(String) in the type Runtime is not applicable for the arguments
(InputStream) , Any suggestions ? Thanks
Runtime runtime = Runtime.getRuntime();
InputStream lic = this.getClass().getClassLoader().getResourceAsStream("MyFile.txt");
Process process = runtime.exec(lic);
You can not execute an input-stream, it’s just a collection of bytes, not a file.
You should store this file somewhere else inside your project (like a resources folder) and use the path to open the file. Here’s how it would look like: