How to have a program print it's location? [duplicate] - java

This question already has answers here:
How to get the current working directory in Java?
(26 answers)
Closed 2 years ago.
I have a java program and I want it to be able to print out its location on the computer. For example, if I were to place the program in the Downloads folder, and run it, it would print out the path to the file.

new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation()
.toURI()).getPath();
make sure to change the Myclass.class stuff
then system.out.println(File)

Related

Transfer the file from source to destination only if the file is not being written into [duplicate]

This question already has answers here:
Get the metadata of a file
(5 answers)
How do I check if a file exists in Java?
(19 answers)
Closed 2 years ago.
Basically i want to do a check wherein the file that needs to be picked up from the source to ensure they are still not being written into and then pull the file and move to destination which i have done
So i want to add a logic to check in java
presentime-filetime>5 minutes
How can i go about doing this in a java function and then process the file to a different location

eclipse does not open my Javafx project [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
My problem is when in an open javafx project and try to run it without editing it, an error appear like this, and everything install for java FX.
You should check whether your getClass().getResource() call actually returns a non-null value. I assume your css-file is not in the right place.

Can we undo file.delete() function in java? [duplicate]

This question already has answers here:
Using Java's File.delete() method
(4 answers)
Closed 6 years ago.
I was trying to delete some duplicate files in my folder which is around 230GB. Therefore, I searched for files with the names _2 or _3 and use the
file.delete();
However, it deletes the files that I wasn't expecting it. Can I undo that process or are those files deleted permanantly?
The Files are gone. See this Question below
http://stackoverflow.com/questions/11106850/using-javas-file-delete-method
So, about the workaround, If this was on windows, using recovery tools like "File Scavenger" might help you out.

Verify Root Access: How to do? [duplicate]

This question already has answers here:
Determine if running on a rooted device
(28 answers)
Closed 9 years ago.
I wanted to know how I can do to see if there are root permissions. What education do I use to verify that in / bin there is the su file? Thanks
Just try
ls /bin
and see what you get

What would be the most diffident way of file copying using java? [duplicate]

This question already has answers here:
Standard concise way to copy a file in Java?
(16 answers)
Closed 10 years ago.
I need to write a application to copy files(.jar,.xml,.sql,.exe) from different location to some specific location What would be the most efficient way of file copy using java?
Use java.nio.file.Files.File#copy which intoduced in java 7. Example -
Files.copy(source, target, REPLACE_EXISTING);
This is covered, in some detail, in Basic I/O tutorial

Categories

Resources