更改每个人的权限时的ClassNotFoundException HttpServletRequest,java.io.File

更改每个人的权限时的ClassNotFoundException HttpServletRequest,java.io.File,java,file,Java,File,我试图设置文件的权限,因为我收到警告和NoClassDefFoundError。之后,我尝试使用 file.setWritable(true,false); file.setExecutable(true,false); file.setReadable(true,false); 但不起作用,文件是这样创建的: private static final java.io.File DATA_STORE_DIR = new java.io.File(System.getProper

我试图设置文件的权限,因为我收到警告和NoClassDefFoundError。之后,我尝试使用

file.setWritable(true,false);
file.setExecutable(true,false);
file.setReadable(true,false);
但不起作用,文件是这样创建的:

private static final java.io.File DATA_STORE_DIR
        = new java.io.File(System.getProperty("user.home"), ".store/calendar_sample");
这是针对GoogleCalendarV3API的,我使用的是Mac,在这里,项目执行没有问题,但是当我在Windows7中运行它时,问题开始显现,并且.jar崩溃

当文件没有权限时,似乎会触发异常

这是全班同学

public class GoogleCalendar2 {

private static final String APPLICATION_NAME = "expeDiente";
private static final java.io.File DATA_STORE_DIR
        = new java.io.File("C:\\\\\\\\", ".store/calendar_sample");
private static FileDataStoreFactory dataStoreFactory;
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
private static HttpTransport httpTransport;
@SuppressWarnings("unused")
private static Calendar client;
String id = "";

public GoogleCalendar2() throws GeneralSecurityException, IOException, Exception {
    DATA_STORE_DIR.setWritable(true, false);
    DATA_STORE_DIR.setExecutable(true, false);
    DATA_STORE_DIR.setReadable(true, false);

    httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

    Credential credential = authorize();

    client = new Calendar.Builder(httpTransport, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME).build();

}

/**
 * Authorizes the installed application to access user's protected data.
 */
private static Credential authorize() throws Exception {
    Set<String> scopes = new HashSet<String>();
    scopes.add(CalendarScopes.CALENDAR);
    scopes.add(CalendarScopes.CALENDAR_READONLY);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            httpTransport, JSON_FACTORY, "user id google", "user secrets", scopes)
            .setDataStoreFactory(dataStoreFactory)
            .build();
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
 }
}
公共类谷歌日历2{
私有静态最终字符串应用程序\u NAME=“方便”;
私有静态最终java.io.File数据\u存储\u目录
=新的java.io.File(“C:\”、“.store/calendar\u sample”);
私有静态文件数据存储工厂数据存储工厂;
私有静态最终JsonFactory JSON_FACTORY=JacksonFactory.getDefaultInstance();
专用静态HttpTransport-HttpTransport;
@抑制警告(“未使用”)
私有静态日历客户端;
字符串id=“”;
public GoogleCalendar2()抛出GeneralSecurityException、IOException、Exception{
数据存储目录可设置写(真、假);
数据存储目录setExecutable(真、假);
数据存储目录setReadable(真、假);
httpTransport=GoogleNetHttpTransport.newTrustedTransport();
dataStoreFactory=新文件dataStoreFactory(DATA\u STORE\u DIR);
凭证=授权();
client=new Calendar.Builder(httpTransport、JSON\u工厂、凭证)
.setApplicationName(应用程序名称).build();
}
/**
*授权已安装的应用程序访问用户受保护的数据。
*/
私有静态凭据授权()引发异常{
Set scopes=new HashSet();
添加(CalendarScopes.CALENDAR);
添加(CalendarScopes.CALENDAR\u只读);
GoogleAuthorizationCodeFlow=新建GoogleAuthorizationCodeFlow.Builder(
httpTransport,JSON_工厂,“用户id谷歌”,“用户机密”,范围)
.setDataStoreFactory(数据存储工厂)
.build();
返回新的AuthorizationCodeInstalledApp(流,新的LocalServerReceiver())。授权(“用户”);
}
}
这就是我试着运行罐子时得到的结果

这与Java无法在Windows 7上解决系统属性“user.home”的问题有关。在Unix和类Unix操作系统上,此属性值将被评估为环境变量
$HOME
,例如
/HOME/my_username
。但是,在Windows 7上,Java不会将其解释为默认用户目录
C:\user\my_username
。有关详细信息,请参阅相关网站

我尝试使用user.dir,但仍然收到相同的警告。像使用C:\as目录吗?我不知道什么是“硬编码”是的,但在Java中你需要放一些类似“C:\\\”。好吧,如果我使用System.getProperty(“user.home”)、“.store/calendar\u sample”并改为“C:\\”、“.store/calendar\u sample”这样的东西,我会得到同样的警告,当你调试你的程序时,它似乎不起作用,调用该行时,是否看到正在创建的文件
C:\.store\calendar\u sample
?它也应该是“C:\\”,只有两个反斜杠。