Skip to content

Tag: file

Tinylog Android, is it possible to clear the file?

I’m using the Tinylog library with the “rolling file” function to write logs to a file. Sometimes I need to clear a file. Tried to do it with normal Java methods but it breaks the file and makes it hard to read. Is there a way to clear the log file at any point so it doesn’t break? Ans…

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>&gt…

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 fr…

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…

Create directory without manage all files permission

How can i create directory in ( /storage/emulated/0/ ) without manage all files permission. This is my code : On android 11 its not working because it need manage all files permission. Answer From SDK 30 you can not access all file system without using MANAGE_EXTERNAL_STORAGE. If your app is in following cate…