java 解析 ical_使用Java编写.ics iCal文件

我正在尝试使用java实现我自己的iCal创建者,由于某种原因,我无法识别我的.ics文件.我想知道我做错了什么,我可以得到与维基百科的示例完全一样的输出. .ics文件和程序生成后的文件之间有什么区别.

他们的例子:

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();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值