通过Eclipse下载并处理ICS文件

时间:2019-01-09 11:06:28

标签: java eclipse download icalendar

我想通过eclipse下载带有超链接的 ics 文件(它会永久更新,所以我总是需要最新版本),在它可用后,我想读出该文件,所以我可以使用它。
而且,如果需要将文件下载到文件系统,那么我想再次将其删除。
不幸的是,我还没有在互联网上找到任何帮助,我也不知道该怎么做。

示例ICS网址:americanhistorycalendar.com/peoplecalendar/1,328-abraham-lincoln?format=ical

我希望有人能提供帮助。告诉我,如果您需要更多信息。

1 个答案:

答案 0 :(得分:0)

解决了我自己的问题:

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;
}
相关问题