【发布时间】:2014-08-16 01:23:28
【问题描述】:
我正在尝试设置文件的权限,因为我收到警告和 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");
这是用于 Google Calendar V3 API,我使用的是 Mac,这里项目执行没有问题,但是当我在 Windows 7 中运行它时,问题开始出现并且 .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");
}
}
这是我尝试运行 jar 时得到的
【问题讨论】: