This question already has answers here:
How Do I Eject a Volume in Java?
(2 answers)
Closed 3 years ago.
I know that questions like this have been asked before, but I couldn't find any more recent ones and I have a twist to my question.
I've developed an application in Java that is designed to run on removable media, and work on both Windows and Mac. I would like to add a button to safely remove/eject the device, if it is supported (i.e a USB drive). Is there a command line for each operating system that would allow me to do this?
I know that it can be done by an application running on the device to be ejected, because I've seen one that does it, but obviously I understand there are certain limitations to Java.
Thanks in advance
This is something that you will have to do by invoking an auxiliary application. These applications are not platform independent as you wish. So, to do that, find out which OS you are on by using System.getProperty("os.name") and invoke the appropriate command for the detected OS. Invoking applications is done with Runtime.getRuntime().exec(). Search for the commands you need for each OS.
Related
This question already has answers here:
Global keylogger in Java
(3 answers)
Closed 6 years ago.
I have been searching for a while now for a library that allows me to know which Key-Event was pressed. But not in a focused program/text-field or anything else but as a process that runs in the background.
I'm not trying to write a keylogger but I want to create a program that lets me create shortcuts for key-combinations.
I don't think Java has native support for something like this. Java is really a language of abstraction, it gets you further away from the OS to make developing easier - but also for security purposes.
Key events are core to the OS so you will (likely) need a language or a library has that capability. Check out JNativeHook.
You can achieve this using JNI and Global System hook. Global System hook applies a Key Logger to the whole computer and not the JVM therefore allowing you to capture key presses outside of the JVM.
An example implementation of it can be seen here
This question already has answers here:
How to find how much disk space is left using Java?
(4 answers)
Closed 8 years ago.
I am looking for simple solution for finding total disk space and available space of a remove machine using java program.
Please help
Update
There are questions already similar to this with primarily focus on local machine. I was looking solution for remote machine.
The easiest way to get the remote machine information and also safe way to do
is to SSH to the server from Java and get the necessary information from.
use JSch Library for SSH connection to server.
for an example look here
This question already has answers here:
How can a program control another program?
(11 answers)
Closed 8 years ago.
I wonder is possible to make a bot writen in JAVA, which will open some program(program is under windows), click on the button in this program and type some data, check status of this program(login or logout, this is client for online game).
Which JAVA tools I need ? I think that java robot lib is not enough for this.
Thanks in advance.
You cannot do this using JAVA.
JAVA is a language which is loosely coupled with operating systems, so it can only receive mouse/key messages from underlying OS. Among all the tasks you mentioned , it can only start the program by using Runtime.execute.
If you want to implement a software like this ,you should use Visual Studio and use Microsoft technologies.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Detect if Java application was run as an admin
How do I find out if the user running my Java application is a Windows administrator, or not?
Java is cross platform and there is no way to see directly whether the user is a Windows administrator.
In general you should check for the priviledges you need instead of relying on some knowledge about what it means to be an administrator on Windows. For example, if you need to write to a file, check directly that the file is writeable etc...
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How can I detect the Android emulator?
Is there a way to reliably and programatically determine if my app is running on an AVD vs. real hardware?
Previously I've had good luck checking MAC addresses, but I'm not sure if AVD's all have the same first AA:BB:CC portion (like stock VMWare or VirtualBox Virtual Machines do).
I use a lot of Log.i() calls while learning to code Android Java. But this logging will murder a real phone (and is just rude to waste the user's space and resources). I figure I could wrap my Logging like this pseudo-code:
public void Loggy(String s)
{
if (!DEVELOPER) return true;
Log.i(MYAPP,s);
}
I've searched and the closest I see are people asking the same question but for iPhone.
See How can I detect when an Android application is running in the emulator?