通过 Eclipse 下载和使用 ICS 文件
downloading and working with ICS-file via eclipse
我想通过 eclipse 下载一个带有超链接的 ics 文件(它会永久更新,所以我总是需要最新版本),在它可用后我想读出来文件,所以我可以使用它。
而如果文件需要下载到文件系统,我想最后再删除。
不幸的是,我还没有在互联网上找到任何帮助,我不知道该怎么做。
示例 ICS url:americanhistorycalendar.com/peoplecalendar/1,328-abraham-lincoln?format=ical
希望有人能帮忙。如果您需要更多信息,请告诉我。
解决了我自己的问题:
public String readICS() throws IOException {
String fileUrl = "http://..."; //ICS-Url
BufferedInputStream in = null;
String ics = null;
try {
in = new BufferedInputStream(new URL(fileUrl).openStream());
byte data[] = new byte[1024];
while (in.read(data, 0, 1024) != -1) {
ics = ics + new String(data);
}
} finally {
if (in != null)
in.close();
}
return ics;
}
我想通过 eclipse 下载一个带有超链接的 ics 文件(它会永久更新,所以我总是需要最新版本),在它可用后我想读出来文件,所以我可以使用它。
而如果文件需要下载到文件系统,我想最后再删除。
不幸的是,我还没有在互联网上找到任何帮助,我不知道该怎么做。
示例 ICS url:americanhistorycalendar.com/peoplecalendar/1,328-abraham-lincoln?format=ical
希望有人能帮忙。如果您需要更多信息,请告诉我。
解决了我自己的问题:
public String readICS() throws IOException {
String fileUrl = "http://..."; //ICS-Url
BufferedInputStream in = null;
String ics = null;
try {
in = new BufferedInputStream(new URL(fileUrl).openStream());
byte data[] = new byte[1024];
while (in.read(data, 0, 1024) != -1) {
ics = ics + new String(data);
}
} finally {
if (in != null)
in.close();
}
return ics;
}