Java FileOutputStream set file icon - java

I have a FileOutputStream. I want to "save" this file and give it a own icon that is saved in the ressource-folder.
Here's the code:
ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream(path));
oout.writeObject(this.categoryDAO);
oout.writeObject(this.toDoDAO);
oout.flush();
oout.close();
In the "path"-variable is the whole path including filename. I want the icon for that file.
Is it possible to set a own icon or do I have to do it with otherwise?

No, you can't do this just from Java.
Icons are associated with a file extension, so if the file ends with '.txt', then it might show a page, while an image with '.jpg' will show a thumbnail or a picture icon.
This is built in at the OS level. Whenever you install new applications, they tell the OS what extensions they can handle. When the OS shows you files in your explorer, it looks at the list of applications that can handle the extension, and shows the appropriate icon.
If you want a specific icon, you can register your own specific file extension, and when you save your files in Java, use that extension. The exact details of how to do that are OS dependent, and not related to Java, so out of the scope of this answer.

I assume you are under windows and you cannot change the icon of a file (except for shortcut or .EXE file).
What you can change, is the default icon for the file type.

Related

How to assign an icon to a file?

I am making a program that stores information in a file with a custom extension. I was wondering If it is possible to assign it an icon within the program so that the icon will show the file with the icon anywhere on the computer? For example how all Microsoft word documents have the word icon.

Find out the extension of an image, if that image doesn't have any extension

Our project has an image uploading module using Java. While uploading image, if a user uploads an image with an extension of jpg/jpeg/gif/png etc., whatever the extension, we save it with same extension by changing just its name.
But here is one small issue. Suppose the user removes the extension of that image manually (of course it never happens, but let's consider it as example) and uploaded the file, it doesn't have any extension.
Is there any way to find out extension/format after reading that image (like after reading the image using getBufferedImage())?
Here I can't use mimeType as we are taking mime type from user while uploading image itself. The user may upload image without an extension, by selecting the mimeType as "image/jpeg".
There are java libraries like mime-util or jmimemagic that can detect the file type from the pure content.

localizing raw resources in android app

I want to serve local language content in my app. I am reading a .txt file in res/raw folder using FileReader (Buffered one). I have read that Android can automatically translate text for values/strings.xml file.
Is the same possible for raw text files. I am looking for minimal code changes.
Android does not automatically translate any files.
You as a developer can translate them and put the resources in appropriately qualified folders, like values-en, values-fr and so on.
These qualifiers work on all folders under res, including the raw folder.
No code changes are required, as Android will automatically pick the correct file upon runtime. However, you should always keep a copy in the default folder with no qualifications in case the app is run on a device for which you do not have content available.

Export/Save jLabel contents to new folder

I have a program that perform two functions: Upload image, Export image.
after uploading an image it will shown in a jLabel,
my question : is there any way to save this image and export it to a new folder on desktop or any place the user choose?
for example, if I uploaded an image and its displayed on jLabel, when I press the Export button the program should open a dialog window asks me to choose a name for a folder and save the image in it.
Thanks in advance!
It sure is possible!
Take a look a JFileChooser, ImageIcon, and ImageIO and specifically search around for tutorials on using ImageIO

Get 48x48 icon size of any file, folder or drive in java

How to get 48x48 icon size of any file, folder or drive in java?
SWT has this functionality. Look at the "Program" class. I don't think standard java can achive this without JNI or another native layer.

Categories

Resources