How to assign an icon to a file? - java

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.

Related

How to differentiate text and images from a PDF file using java?

So i have to make an android app using Java that reads a PDF File and displays it on screen without using other programs(such as PDF Reader). How to make a distinction between text and image in that file? in other words, there is text and in between text ther is an image, how do i verify where it is text and where is an image?
PDF files don't work like that.
It is a complex format, and there is a lot more data in the files than just text and images, such as metadata and formatting.
If you want to handle PDF files in your app, you should use a PDF library, such as the ones listed here:
https://camposha.info/android-examples/android-pdf-libraries/#gsc.tab=0
How exactly to load text will depend on the specific library you choose, and you should check the relevant documentation.

Modify information inside jar file

so my question is about programm written in java. I created sort of top 5 scores ranking using a text file for my game. It reads top scores, that are already saved in a text file, and when you finish the game, it writes to this text file, then reads it and updates top scores shown in the game. But now i'm stuck in packaging my game to a jar file. It seems impossible to modify a text file inside a jar file...
So what are possible solutions here? Forcing a programm to create new text file in a path where jar file is is one of the solutions, but maybe there is some easier solution that won't create additional file on a computer.
I would recommend having an external text file stored somewhere relative to your program. Then have your program modify it as it needs.

Creating your own file for your JAVA app containing informations and images (on single file only)

Situation: I've created a (JAVA) journal app which you can write your own journal and put images to the context.
Problem: Now I'm trying to create a file containing all the informations including text, images and settings. I want to save it on a SINGLE file only. I've tried so many things like Converting Image to binary object and appending it to the file, Serialization, BufferedImage. But whenever i try to read the file, i can't get the image back. only the texts.
Concept: On microsoft word we can make a document, we can write text and put images then we save it to a single file with ".docx" extension.
Is there any way to implement this concept to my app?

Java FileOutputStream set file icon

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.

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

Categories

Resources