java 解析 ical_使用Java编写.ics iCal文件
我正在嘗試使用java實(shí)現(xiàn)我自己的iCal創(chuàng)建者,由于某種原因,我無法識別我的.ics文件.我想知道我做錯了什么,我可以得到與維基百科的示例完全一樣的輸出. .ics文件和程序生成后的文件之間有什么區(qū)別.
他們的例子:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:uid1@example.com
DTSTAMP:19970714T170000Z
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR
我的.ics文件
BEGIN:VCALENDAR
VERSION:1.0
PRODID://Elara/lofy/tanare/delp/314sum2015//
BEGIN:VEVENT
UID:uid1@example.com
DTSTAMP:19970714T170000Z
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR
這是用于生成.ics文件的代碼.
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
public class iCal {
private String version = "VERSION:1.0
";
private String prodid = "PRODID://Elara/lofy/tanare/delp/314sum2015//
";
private String calBegin = "BEGIN:VCALENDAR
";
private String calEnd = "END:VCALENDAR
";
private String eventBegin = "BEGIN:VEVENT
";
private String eventEnd = "END:VEVENT
";
public void iCal(){
}
public void write( String name ){
StringBuilder builder = new StringBuilder();
builder.append(name);
builder.append(".ics");
String testExample = "UID:uid1@example.com
DTSTAMP:19970714T170000Z
ORGANIZER;
CN=John Doe:MAILTO:john.doe@example.com
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
";
try {
File file = new File(builder.toString());
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(calBegin);
bw.write(version);
bw.write(prodid);
bw.write(eventBegin);
bw.write(testExample);
bw.write(eventEnd);
bw.write(calEnd);
bw.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}
}
}
總結(jié)
以上是生活随笔為你收集整理的java 解析 ical_使用Java编写.ics iCal文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 解决webupload在同一页面实现多个
 - 下一篇: IoT 物联网设备该如何选择固件升级 O