Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java give admin rights in eclipse [duplicate]

Tags:

java

eclipse

I'm writing an application that should be able to save a text file to any location. When I'm running the code in eclipse I get the following Exception:

java.io.FileNotFoundException: C:\myFile.txt (Zugriff verweigert)

"Zugriff verwiegert" is german for permission denied.

I can write to C:\Users\MyUser\Documents though.

I did some research and found out that the application needs administrator rights. If that is true, how can I run it as administrator in eclipse?

My code to write the file:

try {
        PrintWriter writer = new PrintWriter("C:\\myFile.txt", "UTF-8");
        writer.print(script.toString());
        writer.close();
} catch (FileNotFoundException | UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
}

Edit: Stackoverflow associates my question with the following one: How do I elevate my UAC permissions from Java? But I want to know if it is possible in eclipse! ;D

like image 441
Lahzey Avatar asked Sep 19 '25 12:09

Lahzey


1 Answers

Run Eclipse as Administrator, and you will be able to write anywhere on the file system

like image 73
Jeeter Avatar answered Sep 22 '25 03:09

Jeeter