I would like to know if scanner in Java is able to read pdf files? If yes, how?
This is what I have, but it ain't working:
Scanner scan = new Scanner(mypdffile);
String Result = "";
while(scan.hasNext()) {
Result += scan.nextLine();
}
I would like to know if scanner in Java is able to read pdf files? If yes, how?
This is what I have, but it ain't working:
Scanner scan = new Scanner(mypdffile);
String Result = "";
while(scan.hasNext()) {
Result += scan.nextLine();
}
No Scanner
will not work as you intend with PDF files. See this question for suggestions on how to read PDFs in Java. The TL;DR is that you probably want to use a library.
I ended up using streams to read from the pdf files, as I was looking for an approach without using PdfBox,etc.
dos is my dataoutputstream
try
{
FileInputStream fin = new FileInputStream(mypdffile);
int read=0;
byte[] buf=new byte[1024];
//read in file
while((read=fis.read(buf))>0) {
dos.write(buffer,0,read);
dos.flush();
}
dos.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}