How to stop creating thumbs.db files in compression using java - java

I am trying to compress a folder to zip and extract the same folder using java. When i zipped or unzipped the folder the files which are in the folder compressed and extracted successfully. But a Thumbs.db file is creating with in the folder.
I want to delete/avoid the Thumbs.db files before/after compressing to zip or extracting from zip programmatically.
Is it possible in java ?

Thumbs.db is usually a file with the system and hidden attributes (see attrib.exe ) and therefore invisible in the Explorer (unless you set the Explorer to show all files including system files).
When you extract the file you should set it's attributes accordingly.
How to set a file attribute using Java is already described here: https://stackoverflow.com/a/36465283/150978

Related

Writing to text file created manually inside app

Is it possible in Android, to manually add a file inside a project and then, modify it? Example:
"I have a test.txt file in the following path: "app/src/data". I would like to make a method to write a given String in the test.txt file."
Is that possible? I been looking everywhere, but can't seen to do such an easy task.
If you mean modifying files inside the APK itself then it's not possible. Besides, the folder structure you see in the project is not the final structure on the APK (just unzip your APK, it's a .ZIP really): Fpr example, the source directory is all compiled into a classes.dex. The res/ directory is compiled and fully copied ...
Take a look at How to write files to assets folder or raw folder in android?
and https://developer.android.com/training/basics/data-storage/files.html
You can read raw files stored in /res/raw, or assets stored in assets/ , but you cannot modify stuff inside the APK itself.
What you can do is create and modify as many files as you wish from the different places Android gives to any app, such as:
CACHE directory (context.getCacheDir() -> /sdcard/Android/data/your.package/cache
External files (context.getExternalFilesDir() -> /sdcard/Android/data/your.package/files
Arbitrary directories in the SDCARD.

Zipping single file in a single zip without creating a folder

In java most of the zipping apis zips the single file by creating a folder.
For example in windows if we choose to right click-->Winzip-->Add to selected_file_name.zip it creates selected_file_name.zip and if we extract we directly get file rather than a folder and within folder a file.
After extracting by selecting a extract to here only file should come rather than a folder and then a file within that.
Can we do the same using any java api ?

Read only file in Zip archive

I'm trying to generate a zip file with java.util.zip API and I haven't found any way to set zip entry as read only file. I would like to create a new ZIP archive, put files inside it and set read only flag for all those files that appear inside of the ZIP file (on Windows platform).
I am aware that java.util.zip API works with Streams instead of File objects (File object has method setReadonly()).
I also tried with Apache Commons Compress API and haven't found solution as well.
Please help!

Get contents of a directory in a ZIP file in Java

I have some default configuration files inside my application jar that I would like to save to the file system if they don't already exist. I would like it to keep the directory structure too. Example:
Jar file
-configs/
-main-config.cfg
-another-file.txt
-stuff/
-another-file.cfg
-com/
-META-INF/
I would like the contents of configs/ to be mirrored to the file system, including the subfolder.
Use JarFile.entries to get an enumeration of all of the entries in your Jar file.

Bundle APK with dynamic application properties file?

Is it possible to bundle or generate an APK with some sort of dynamic file where you can set different application properties, such as background colors, etc?
Thanks!
This is a high level answer, but assuming they are downloading the apk file from a webserver, there's nothing stopping you from generating some sort of configuration file, dropping it in res and accessing it from your application. An apk file is simply a "zip" file with some extra trimmings. It would not be difficult to have your classes.dex file along with the other requisite files on the server, and create an apk file on the file using some sort of zip library. Now, I'm not familiar off the top of my head how you could access an arbitrary file (such as an xml file or .properties file) out of the res folder, but a little bit of googleing should give you that answer.

Categories