【发布时间】:2014-03-25 11:02:19
【问题描述】:
我有一个要求,在我的屏幕标题标签上和底部 屏幕的一个按钮在那里。我想在这个标签之间显示 PDF 文件 和按钮我将如何实现这个?当我尝试打开 PDF 时,它已满 屏幕空间。
File file = new File(getFilesDir(), "mypdf.pdf");
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//System.out.println(file.exists() + "!!");
//InputStream in = resource.openStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
//Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
System.out.println("read " + readNum + " bytes,");
}
} catch (IOException ex) {
ex.printStackTrace();
}
byte[] bytes = bos.toByteArray();
//below is the different part
File someFile = new File("java2.pdf");
try {
FileOutputStream fos = new FileOutputStream(someFile);
fos.write(bytes);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file://" + getFilesDir() + "/java2.pdf"),
"application/pdf");
startActivity(intent);
【问题讨论】:
标签: android pdf webview filereader