I am working with a Java Application. In this, I must copy a file from source to Multiple Destinations. The destinations are various USB drives. (ie) I'm copying a file for desktop and sending to a number of USB drives. Here, my problem is, I am sending files to all USB drives I attached, now I need to make the files UN-deletable. The undeletable process will be done in a single event. For example once I click the ok button, the Files, which are present in all USB drives are made undeletable. Any idea how to do this.
When copying source file to other files, put the destination File objects in a collection. Then, in the event handler for your 'set read only' button, loop over that collection and call setReadOnly() on each File.
not very sure I understand your question correctly.
maybe you can store the directories and when you click the OK button, you iterate these directories and set them to undeletable one by one?
Related
I'm developing an app that has the functionality to upload all video and photo files to an external server, and I would like to offer the user the possibility to empty their photo and video directory...soon there is some easy way to do that? erasing everything at once
I assume your app already has a way to get access to the path to the directory you want to clear, and a permission to access the storage. Now having the path to the directory you could simply
File(pathToDirectory).list().forEach{ it.delete() }
Customize the behavior based on your needs. For example, you could recursively call the function containing the code above to clear a directory and all included subdirectories, or you could leave folders untouched and just delete files. For that, there are fields isFile and isDirectory
I am using talend to pickup file from source folder and transfer to the destination folder,however i want to pickup the file for processing only if the file is completely written in the source or not during/when the file is actively being copied into the source folder.
I realize that in talend when trying to move the file from source to dest. when the file is being still written into source folder-it shows an error message that "file is still being used by another proces" however i dont want that error to be triggered for each every run,i would want to skip and move to the next file in the iteration folder.
Can i use a twait or twaitforfile between components or add java code to handle it such that
"presenttime(sysdate)-filetime(arrivaltimeinto the folder)>timedifference(lets say around 3-5 minutes)"
Only if the condition is satisfied move the file to destination folder.
Please suggest which is the best efficient way to handle this.
In advanced settings of tWaitForFile, you have an option "WAIT_RELEASE" : you can set it, and when a file is detected, it will perform a 2d check XXXms after the first one, to make sure that the file is released (so that it is not actively being copied to the repository). When the file is fully copied, you are then able to use it.
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
Is it possible to drag a "virtual" file from Java swing application and drop it onto windows desktop?
By "virtual" I mean "not local" file that needs to be downloaded/prepared which could potentially take a long time. I have a client-server application that shows a view of remote files. When user drops that file on desktop, I would like to receive a notification of the destination folder which I would use to start the download process with the Java application.
Please offer any help or guidance as I've been looking for a solution for a while now.
I'm working on something similar myself, and I have some unfortunate news for you: Windows cannot handle promised files, nor does it inform your java application as to where the files are dropped. Simply put, there is no way to handle remote drag-and-drop via the DnD api only.
You need to create empty files in some temp directory somewhere, and hand windows those files when the mouse leaves the swing window. You also need to set up a WatchService on the local filesystem to receive notification of file creation. After DropEnd, you check for empty files of the correct name but not in your temp directory, and effect the transfer at that point (move the remote files into the empty files that were dropped).
I have a requirement that, User will see the list of files in the page which is the list from directory. From there they will select multiple files and they click on view button. Then we need to read the corresponding files from Drive and need to open all the files which are all user has selected. I need to implement this using Struts2/servlet.
From what I userstand the user sees the content of a directory which is located on the server, right?
Further, you display a list of files along with some selection method (checkboxes ?) which the user uses to select files and then clicks the view button.
If I am correct, you could use javascript to open a new tab/window or dialog (e.g. a jQuery dialog) which reads the file or its contents from the server. Just iterate over the selected entries in the list and pass them one by one to the JavaScript function that opens the tab/window/dialog.
It is not clear if you do want to
open each file in the client's browser, or
download each file to the client's file system, or
download an archive containing all the files to the client's file system;
In 1. or 2. you need to create multiple requests, targeting multiple windows, using target="_blank", or by AJAX, etc .
By manipulating HttpResponse Header objects, you can instruct the browser when to open or download a file: Content-Disposition: inline; will try to open it inside the browser, while Content-Disposition: attachment; will perform the default operation (open with default desktop application, download, or ask if none of the previous was marked as default by the user)
Keep in mind that you may encounter several possible problems by opening or downloading multiple files at once; it could overload/crash the client, overload/crash the server, cause problem of bandwidth etc; what if the user choose 100 files ? You would open 100 tab, or 100 windows, or ask 100 times where to save each file, etc...
If you want to create a dynamic ZIP instead, you can find a kick-off example on how to do it in Struts2 here, (using an Action like a Servlet, and returning NONE);
My files were from database, yours are from file system, but the code is the same.