There are examples for JMH here. They are present as multiple links within the directory samples/. I can right click on the link and save the files one by one. Is there any way to save all of them at once? Rather than using any download managers! Can we use Java URL class with regex to open the similarly named files and save it?
Related
my program on startup will:
1. search for a file
2. read the file
3. and set a string to the files contents
But the way ive done it it will only work if they have the exact path that i am hard coding in.
i want the path to adapt to other computers. I think i should use the Path class but ive just heard about that so not sure where to go.
basically i want it to search for a file on any users desktop, and if its not there make it.
if you need some code to clarify i can post it just let me know
I could think of two options.
You can simply specify a file name such as "myFile.txt", so the program will search this file in its program/project folder.
If it does not exist you can write the code to create it in the program folder, instead of hard coding any absolute path.
Else, you can try using the javax.swing.JFileChooser class to pop up an Open and Save dialog box.
This will give the end-user the freedom to select any file for reading and writing.
I found below two articles with some example on how to use the class. Please refer them for more information.
https://www.codejava.net/java-se/swing/show-save-file-dialog-using-jfilechooser
How to "Open" and "Save" using java
Thanks.
You can use the path "./yourfile.txt". It will search for "yourfile.txt" in the directory ".". That means the project's current directory. Maybe it can help you.
I have an app that accesses words from a csv text files. Since they usually do not change I have them placed inside a .jar file and read them using .getResourceAsStream call. I really like this approach since I do not have to place a bunch of files onto a user's computer - I just have one .jar file.
The problem is that I wanted to allow "admin" to add or delete the words within the application and then send the new version of the app to other users. This would happen very rarely (99.9% only read operations and 0.1% write). However, I found out that it is not possible to write to text files inside the .jar file. Is there any solution that would be appropriate for what I want and if so please explain it in detail as I'm still new to Java.
It is not possible because You can't change any content of a jar which is currently used by a JVM.
Better Choose alternate solution like keeping your jar file and text file within the same folder
I am making a Spring (not Boot!) project right now, with Maven. The user can upload a file, then I store it in the file system. When I start the application, I create a folder with a method annotated with #PostConstruct. I have already tried two ways: create the folder in the same level as the src and target folder, or create it in the target/tomcat folder (I used the ${catalina.base} property). I want to do some conversion on the uploaded file, basically convert it to JSON, and also store the JSON file. Then I want to use these two files inside JSP pages: when the user executes a GET request, my application will return the path of the files, and I want to use the content of the JSON with JavaScript.
So my question is basically: what is the best place to store these files, if I want to use them later for any purpose, and I dont want to use absolute paths. I saw some example when the code creates a folder like: "C:\folder", but that looks weird for me, relative is much better in my opinion.
In addition to what my title says, I am running into problems because their class file is linked as follows:
"var attributes =
{code:'xx/xxxx/xx/xx/xxx/xxx/xxxxx.class'
width:645,height:443,archive:'xxxxx.jar'}"
First, I naively copied the HTML code and it did show a Java Applet Object, but couldn't load it because it obviously didn't find the class. I tried many different addresses to see if I can download the class, but with no success. Does this mean the class can't be downloaded? I'm in the process of asking for their permission and see if we can get it directly from them.
I also thought of another way. Is it possible to embed their whole page as an iframe AND "crop" it so the iframe only displays the area where the Java Applet is located? If this is possible, it would be the best and easiest way.
You certainly can download the the .jar file - they have to be accessible so that browsers can load them. I'd guess you are trying to get the .class file, but it is within a .jar, so get the .jar instead.
I am trying to create a web application that will allow users to upload files online. I am using gwt while using hibernate for database communication. I am able to upload a file to a server, and store it on the server. What I want to do is to associate the files with a user.
I want the user to be able to create folders and store a file in sub folders. my logic was to use the composite pattern to store folders and fileLocations with a user but I am am finding it difficult to implement this so I can show the files and folders within a gwt tree.
What would be the best way to implement a hierarchy of folders and information of the location of a file so it could be displayed in a gwt tree?
What I did have was a User would hold a reference to a root folder and then each sub folder could hold folders or fileLocations. I used the composite pattern to implement the file hierarchy, but when I want to display a the contents of a folder I need a for loop for each list. So if I had a folder within a folder within a folder, that would need 3 nested for loops to show the contents of my folders.
I would like something like this.
What is the best way to implement this file management system?
I assume you aren't actually storing the directories and subdirectores as actual, real-life directories and subdirectories on the server? If you are, I would just have Java iterate the filesystem on the server and return a lightweight client-side representation of the files and folders it found to your GWT front-end for display. Apache Commons IO (specifically FileUtils.iterateFiles, or FileUtils.listFiles, just below it) can help you here.
If you're trying to emulate a file system in a database, you will probably want to do some research on how modern file systems store and look up files and how to implement and iterate over such data structures (you'll need some sort of loop or recursion). Some research into B-trees may help, as may this database of data structures (trees will be most helpful).