Skip to content

Tag: file

How can I get Java to read all text in file?

I am trying to get Java to read text from a file so that I can convert the text into a series of ascii values, but currently it only seems to be reading and retrieving the first line of the txt file. I know this because the output is much shorter than the text in the file. The text in

How to convert https url to File in Java?

I have an https url which is of String format. How can I convert it to File? I tried this but I’m getting error – URI scheme is not “file” Answer FileUtils.copyURLToFile worked well for me. Reference –

Efficient way to get line number of bunch of string from a file

I want to search a list of strings from the file and get the line number. I am looking for an efficient way to do it. I don’t want to search one string at a time and open and close file. Answer Store the line numbers where each String appears in the file using a HashMap<String, List<Integer>>. This will allow

How can I output a random image when in a jar file?

The below code works when running from my editor but the image fails to load when compiled into a runnable jar file with eclipse. Could someone please suggest how I can modify my code or editor to load the files when compiled. I have read other methods of accessing files but since I need to select randomly from a folder,

Java – Method is not creating file text file

I got this method for creating a log file: but the file is not created, instead I get this error: Whats the fix for this? Answer Try putting the email.log directly as a child of the project root folder and a peer of src. project_root/src project_root/email.log (your file) This is probably happening because of the relative path usage on your

Cannot be resolved to absolute file path because it does not reside in the file system

My Code: I have already tried instead of .getFile(), extractJarFileFromURL or resource.getInputStream() but all this does not work. When I package my project and run it as a jar file and it tries to open the following file it always returns the following message. Error: class path resource [assets/OPTIONS_DE. docx] cannot be resolved to absolute file path because it