我正在下载生成的ics日历,在下载ics日历时,它正在下载名称,如" ics"。我想添加像" test.ics"这样的名字,但我无法添加名称。请帮我动态添加名称到下载的ics文件。使用下面的代码将ics文件转换为字节。
private byte[] calendarAsByteArray(net.fortuna.ical4j.model.Calendar calendar) throws FileNotFoundException {
byte[] bytes;
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
CalendarOutputter outputter = new CalendarOutputter();
outputter.setValidating(false);
outputter.output(calendar, output);
bytes = output.toByteArray();
} catch (Exception e) {
throw new IllegalStateException("can't convert calendar to bytes: "+e);
}
return bytes;
}
答案 0 :(得分:0)
您可以将您的bytes数组写入文件并指定所需的文件名:
private byte[] calendarAsByteArray(net.fortuna.ical4j.model.Calendar calendar) throws FileNotFoundException {
byte[] bytes;
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
CalendarOutputter outputter = new CalendarOutputter();
outputter.setValidating(false);
outputter.output(calendar, output);
bytes = output.toByteArray();
FileOutputStream fos = new FileOutputStream("test.ics");
fos.write(bytes);
fos.close()
} catch (Exception e) {
throw new IllegalStateException("can't convert calendar to bytes: "+e);
}
return bytes;
}