我目前不知道问题出在哪里,我恳求帮助。
我正在生成一个ics-文件。 但是,如果我要打开ics-File以获取日历,则会收到以下错误消息:
net.fortuna.ical4j.data.ParserException:第1行出现错误:文件的意外结尾
以下是我的信息: ical4j版本3.0.1 Java:8内部版本181
我的ics输出-文件:
BEGIN:VCALENDAR产品:-// Ben Fortuna // iCal4j 1.0 // EN版本:2.0 CALSCALE:GREGORIAN开始:VEVENT DTSTAMP:20180826T165052Z DTSTART:01180905T000000 DTEND:01180905T000000摘要:ddd TZID:欧洲/柏林 UID:1535302250819-9ed0489f-0320-4a66-8f9c-4af0e62cdedd END:VEVENT END:VCALENDAR
这是我生成calender.ics的代码-文件:
public void createEvent(BookingDate bookingDate, Mandatory mandatory, Employee employee)
throws FileNotFoundException, IOException, ParserException, ConstraintViolationException {
// Create a TimeZone
System.setProperty("net.fortuna.ical4j.timezone.cache.impl", MapTimeZoneCache.class.getName());
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone("Europe/Berlin");
VTimeZone tz = timezone.getVTimeZone();
String pathMandatoryFile = null;
String pathEmployeeFile = null;
// Reading the file and creating the calendar
Calendar icsCalendar = null;
FileOutputStream fout = null;
if (bookingDate.isCreateCalendarMandatoryEntry()) {
// timezone = registry.getTimeZone(mandatory.getTimeZone());
pathMandatoryFile = "calendar.ics";
fout = new FileOutputStream(pathMandatoryFile);
try {
FileInputStream fin = new FileInputStream(pathMandatoryFile);
CalendarBuilder builder = new CalendarBuilder();
icsCalendar = builder.build(fin);
} catch (Exception e) {
}
if (icsCalendar == null) {
icsCalendar = createNewCalender(pathMandatoryFile);
}
}
// Creating an event
java.util.Calendar startCal = java.util.Calendar.getInstance(timezone);
startCal.set(java.util.Calendar.YEAR, bookingDate.getStartDate().getYear());
startCal.set(java.util.Calendar.MONTH, bookingDate.getStartDate().getMonth());
startCal.set(java.util.Calendar.DAY_OF_MONTH, bookingDate.getStartDate().getDate());
startCal.set(java.util.Calendar.HOUR_OF_DAY, bookingDate.getStartDate().getHours());
startCal.clear(java.util.Calendar.MINUTE);
startCal.clear(java.util.Calendar.SECOND);
java.util.Calendar endCal = java.util.Calendar.getInstance(timezone);
endCal.set(java.util.Calendar.YEAR, bookingDate.getEndDate().getYear());
endCal.set(java.util.Calendar.MONTH, bookingDate.getEndDate().getMonth());
endCal.set(java.util.Calendar.DAY_OF_MONTH, bookingDate.getEndDate().getDate());
endCal.set(java.util.Calendar.HOUR_OF_DAY, bookingDate.getEndDate().getHours());
endCal.clear(java.util.Calendar.MINUTE);
endCal.clear(java.util.Calendar.SECOND);
net.fortuna.ical4j.model.DateTime dtStart = new DateTime(startCal.getTime());
net.fortuna.ical4j.model.DateTime dtEnd = new DateTime(endCal.getTime());
String eventName = bookingDate.getName();
VEvent meeting = new VEvent(dtStart, dtEnd, eventName);
// add timezone info..
meeting.getProperties().add(tz.getTimeZoneId());
String uidValue = bookingDate.getIdHash();
meeting.getProperties().add(new Uid(uidValue));
// Add the event and print
icsCalendar.getComponents().add(meeting);
CalendarOutputter outputter = new CalendarOutputter();
outputter.output(icsCalendar, fout);
}
private Calendar createNewCalender(String filePath) throws ValidationException, IOException {
// Saving an iCalendar file
FileOutputStream fout = new FileOutputStream(filePath);
Calendar calendar = new Calendar();
calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(CalScale.GREGORIAN);
return calendar;
}
请问有人可以帮我吗。