Creating file on Windows 7 causes “Access denied” exception

前端 未结 3 1489
灰色年华
灰色年华 2020-12-06 23:03

I have a Java application were the user can create a text file and save it wherever he wants on his computer using this code :

File txtFile = new File( path          


        
相关标签:
3条回答
  • 2020-12-06 23:22

    Windows Vista and Windows 7 have UAC enabled. UAC denies creating new files in SOME locations, without administrative privileges.

    Check your permissions and make sure to execute the java executable in ADMINISTRATIVE Account, OR disable UAC.

    To do that, go to "Start" type in "CMD.EXE" -> right click on the cmd.exe file and Run As Administrator. Then navigate to the location containing the .class file. Then type in java ClassFile and hit enter

    0 讨论(0)
  • 2020-12-06 23:44

    Short answer - no.

    If you need to save to C drive, they need permissions. If this program just needs to create files, you can use the users temp folder. See System.getProperty()

    0 讨论(0)
  • 2020-12-06 23:46

    Are you using cmd , i.e. Dos to run your file or eclipse? Whatever you are using It looks like you are running as default user. in windows 7, UAC by default blocls writimg to system.directory.

    Do the following and hopefully it should work1

    > If cmd.exe
    >      Then when you open run from start menu. Right click it, select run as administrator and  then run your application
    >     
    >     If eclipse/any other IDE
    >     
    >     Close existing, right clicl eclipse,select run as admim and then run your application
    > 
    > Hope this helps
    
    0 讨论(0)
提交回复
热议问题