Witam,
chciałbym zakodować plik pdf Base64. Używam do tego klasy BASE64Encoder:
public class PDFCode {
File file= new File("data/document.pdf");
BASE64Encoder b = new BASE64Encoder();
BASE64Decoder d = new BASE64Decoder();
URL url;
public void convert() throws FileNotFoundException, IOException, URISyntaxException{
InputStream is = new FileInputStream(file);
OutputStream os = new FileOutputStream("data/dat.txt");
b.encode(is, os);
}
}
Wszystko OK, w pliku dat.txt mam zakodowaną zawartość. Jednak chciałbym, aby pliki pdf pochodziły z jakiejś strony:
public class PDFCode {
File file;
BASE64Encoder b = new BASE64Encoder();
BASE64Decoder d = new BASE64Decoder();
URL url;
public void convert() throws FileNotFoundException, IOException, URISyntaxException{
url = new URL("http://mogrodowski.pl/document.pdf");
file = new File(url.toURI());
InputStream is = new FileInputStream(file);
OutputStream os = new FileOutputStream("data/dat.txt");
b.encode(is, os);
}
}
przy wykonaniu metody convert() pojawia mi się wyjątek:
Exception in thread "main" java.lang.IllegalArgumentException: URI scheme is not "file"
Czy ktoś wie jak to zrobić? Z góry dzięki za podpowiedzi.