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.
Related
I have >400 JPG files and a JSON file for each which contains the image tags, description and title. I've found this command
exiftool -json=picture.json picture.jpg
But I don't want to run this for each and every file.
How can I run this command for the folder containing the JPGs and JSONs or is there another way I can batch process these?
Each JSON file has the same name as it's JPG counterpart so it's easy to identify which files match up to each other.
Assuming your JPGs and JSONs have the same filename, but different extesion(e.g. picture001.jpg has an associated picture001.json,etc.), a batch for loop might work.
Assuming you've already cd-ed into the folder and the files aren't nested in folders, something like this should work
( for jpg in *.jpg; do exiftool -json=${jpg/\.jpg/.json} $jpg; done )
Note that this isn't tested. I recommend making a copy of your folder and testing there beforehand to make sure you don't irreversibly damage them.
I've also noticed you're using the java tag. I had to work with EXIF data in Java a while back (on Android then) and I used the JHeader library. If you want to roll your own little java command line tool, you should be able to use Java's IO classes to traverse your directory and files and the JHeader library to modify the EXIF data.
I need to create a Jar file which will read an excel and display as output, the existing data and the updated data.
This file needs to keep on running and displaying the Excel data as output. Any update that has been done on the Excel recently needs to be reflected in the output, along with the previous data.
I know how to create a Jar file, i am also able to read an excel file using Apache POI.
I just need an idea regarding how during every run, if the Excel is updated, that updated values can be displayed.
Do we need to implement threading,synchronization? If so, then how?
Synchronization does only work inside of your Java process. Assuming that an external process creates/updates the Excel file therefore synchronization will not help you.
The best chance you have is to listen for file-system changes of the Excel file (see WatchService class) and access the file after it has been changed.
For avoiding (or better minimize) file access conflicts I would open the file, copy the data to memory and then directly close the file.
Alternatively you could copy the file and then operate on the copied file. In both cases conflicts can still occur if the program writing the Excel file tries to perform changes while you are accessing the file.
Potential errors are errors because of blocked file or inconsistent data.
I have written an Java code that process some data and stores it in .JSON format.
I also have HTML/CSS/Javascript file, that reads that data, and shows it in much nicer way.
So my question is, is it possible to combine Java and HTML code(in one file .jar) so that, for example on a click of a mouse Java opens HTML file in Default browser?
Thanks
Write out the html file to the filesystem (e.g. a temporary directory How to create a temporary directory/folder in Java?) and then open it using the default program: How to open a file with the default associated program
I need to open a file in libgdx for random access, i.e. I need to be able to seek() to different parts of the file (not read sequentially).
Using libgdx I am able to access the file via Gdx.files.internal(), but libgdx's filehandlers don't support random access methods like seek(). I tried using java.io.RandomAccessFile, but it generates the exception No such file or directory, probably because the file is stored internally in the jar file.
How can I access the file using java.io.RandomAccessFile` or alternatively how can i open file for random-access in libgdx?
This needs to work on both Android and desktop platforms.
This is not a Libgdx limitation. You cannot do random access on files stored inside a JAR file (since they're compressed, you need to stream the contents). (I can't find a concise reference for this, but look at the definitions of JarFile and ZipFile: they only let you create streaming file handles).
Libgdx itself runs into this problem. It stores native libraries in a .jar file (the libgdx-natives.jar). To use the files, it extracts them to the local filesystem and uses them from there. See SharedLibraryLoader.java.
As far as I can tell there are three workarounds to chose from:
Remove the need for the random access in your code.
Stream the file from the JAR into memory, and randomly access it there
Copy the file from the JAR into local (private) storage or temp storage (hopefully this could be done once and not re-done on each run of the app).
I made a programme that calculates shortest paths using some data contained in an excel file.
The programme reads all the data in this file to create nodes. if the users input two values, then this programmes searches for the shortest path and returns it.
Now I want the users to be able to add / remove new data to this file. By doing this, they're adding new 'links' or removing existing links. and the users would be able to see the changes they are making on the shortest path result.
However, I found out that most of the example codes on writing on an excel file is to create a new excel file, and copy whatever was in the original file.
I was wondering if there's any way to modify an existing excel file WITHOUT creating a copy of that file. I actually want the original excel file to change itself. because there are various methods (shortest path method) I've created to work with that exact file.
Any help or example codes would be great. Thanks.