3

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

Community
  • 1
  • 1
Lahzey
  • 373
  • 5
  • 17
  • 1
    It looks like you're asking about executing your code at a higher rights level. Have you tried running Eclipse as an administrator? – Thomas Owens Jul 29 '16 at 16:12
  • 1
    Running it as administrator worked. Don't know why I didn't come up with this by myself :D. Thank you – Lahzey Jul 29 '16 at 16:27
  • I'm very glad that stackoverflow doesn't delete "duplicate" questions with the way people mark them. The question that this is apparently a duplicate of says "no, you can't" and gives some workarounds (to a different, but vaguely related problem), while this question has a clean, concise "*Run Eclipse as an admin*" as an answer. – Kröw Jun 02 '19 at 01:06

1 Answers1

7

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

Jeeter
  • 5,887
  • 6
  • 44
  • 67