好吧,我有一个PDF和Android应用程序生成,但我需要标题有系统的日期和时间。 所以我编译了这段代码:
public void createPDF() { Document doc = new Document(); try { Date date = new Date(); String dateTime = DateFormat.getDateTimeInstance().format(date); File sdCard = Environment.getExternalStorageDirectory(); File dir = new File (sdCard.getAbsolutePath() + "/Bitacora"); dir.mkdirs(); File file = new File(dir, "Bitácora "+idetotrocliente.getText().toString()+", "+dateTime+vwfecha1.getText().toString()+etsitio.getText().toString()+".pdf"); FileOutputStream fOut = new FileOutputStream(file);但是当我尝试在应用程序中生成PDF时,日志会给我这个错误:
08-28 21:32:38.950: E/PDFCreator(12425): ioException:java.io.FileNotFoundException: /mnt/sdcard/Bitacora/Bitácora ¡VALOR NECESARIO!, ago 28, 2013 9:32:24 p.m..pdf (Invalid argument)当我删除“dateTime”变量时,PDF生成正确,但我需要日期在标题中。 我能做什么? :(
Well, Im having a PDF generated in and android application, but I need the title to have the date and time of the system. So I compiled this code:
public void createPDF() { Document doc = new Document(); try { Date date = new Date(); String dateTime = DateFormat.getDateTimeInstance().format(date); File sdCard = Environment.getExternalStorageDirectory(); File dir = new File (sdCard.getAbsolutePath() + "/Bitacora"); dir.mkdirs(); File file = new File(dir, "Bitácora "+idetotrocliente.getText().toString()+", "+dateTime+vwfecha1.getText().toString()+etsitio.getText().toString()+".pdf"); FileOutputStream fOut = new FileOutputStream(file);But when I try to generate the PDF in the app, the log gives me this error:
08-28 21:32:38.950: E/PDFCreator(12425): ioException:java.io.FileNotFoundException: /mnt/sdcard/Bitacora/Bitácora ¡VALOR NECESARIO!, ago 28, 2013 9:32:24 p.m..pdf (Invalid argument)And when I delete the "dateTime" variable, the PDF generates correctly, but I need the date to be in the title. What can I do? :(
最满意答案
问题似乎是因为: 。 请参阅Android上文件名中允许的字符数? 。 :是一种保留字符,所以不能在文件名中使用。 尝试使用.replace函数替换为"" (即空字符串)。 然后用它来创建PDF。 另见Android - 如何用另一个字符串替换部分字符串?
The problem seems to be because of :. See What characters allowed in file names on Android? . : is sort of reserved char, so can't be used in filename. Try to replace that with ""( i.e empty string) using .replace function. Then use it to create PDF. Also see Android - how to replace part of a string by another string?
更多推荐
PDF,new,dateTime,date,电脑培训,计算机培训,IT培训"/> <meta name="descrip
发布评论