Java App 无法在 Windows 7 上写入磁盘,为什么? [英] Java App can't write on disk on Windows 7, why?

查看:50
本文介绍了Java App 无法在 Windows 7 上写入磁盘,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 Java 应用程序,并使用 NSIS(或 NSYS...)安装程序将其打包.我的工作很干净,但有时我发现对于一些在 Windows 7 上运行的用户,该应用程序根本无法写入磁盘(它甚至无法写入日志).该应用程序安装在 c:\Programs(或 d 或 e...)上.支持人员说他们通过在 c:\ 中安装来解决它.为什么会发生这种情况?它与Java安全性有关吗?也许在我的 Windows 安装和其他安装中我没有注意到它,因为我关闭了无人机.

I wrote a Java app and I packaged it with NSIS (or NSYS...) installer. I works cleanly but sometimes I found that for some users running on Windows 7, the app won't be able to write on disk at all (it can't even write the log). The app is installed on c:\Programs (or d or e...). People from support say that they solve it by installing in c:\ . Why does this happen? Is it related to Java security? Maybe on my Windows installation and others I don't notice it because I have UAV turned off.

想法?

推荐答案

当您怀疑是不是因为您关闭了 UAC 时,您就大吃一惊.

You have hit the nail on the head when you wonder if it is because you have UAC switched off.

您不应该将日志文件写入应用程序的安装位置,而是需要选择应用程序可写入的位置,例如user.home 系统属性下的目录.

You should not be writing the log file to the location that the application is installed to, instead you will need to pick a location that is writable by the app, e.g. A directory below the user.home system property.

java 应用程序不能这样做而其他应用程序可以的原因与 数据重定向,这会导致对某些文件夹的写入透明地重定向到每个用户的数据存储.我认为 JRE 禁用了此重定向(使用进程资源管理器检查,它没有虚拟化"标记),这意味着在 Java 程序中不会发生透明重定向.

The reason that java applications can't do this and other applications can is related to Data Redirection, which causes writes to certain folders to be transparently redirected to a per-user store of data. I think this redirection is disabled for the JRE (checked using process explorer, which does not have a marking of 'Virtualized') which means that on java programs the transparent redirection will not happen.

如果您希望您的应用程序能够写入应用程序的安装目录,那么最简单的方法是在安装时更改文件夹的权限.

If you want your application to be able to write into the install directory of the application, then the easiest way to accomplish this is to change the permissions of the folder on installation.

这篇关于Java App 无法在 Windows 7 上写入磁盘,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆