java创建文件到c盘拒绝访问,在Windows 7上创建文件会导致“拒绝访问”例外

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 );

Writer writer = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( txtFile ), "UTF-8" ) ); // Error occurs here.

But many users using Windows 7 reported that when saving the file to "C:\", they get "Access is denied" error. I found that this is because they need administrator permissions to save the file in such path in Win7.

Instead of showing a warning message to the user: " You can't save the file at this path ", can i save the file in this path somehow, like if there is a way to have Administrator permissions in Win7 through Java code, or something like that ?

解决方案

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值