Here you can find the source of downloadMobiFromEpubUrl(String href)
public static void downloadMobiFromEpubUrl(String href) throws IOException
//package com.java2s; /**//ww w.jav a2 s.co m * Copyright 2014 Kaloyan Raev * * This file is part of chitanka4kindle. * * chitanka4kindle is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * chitanka4kindle is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with chitanka4kindle. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; public class Main { public static void downloadMobiFromEpubUrl(String href) throws IOException { URL urlEpub = new URL(href); String path = urlEpub.getFile(); path = path.substring(0, path.length() - 4).concat("mobi"); URL urlMobi = new URL("http", "bb.bulexpo-bg.com", path); InputStream in = urlMobi.openStream(); String fileName = path.substring(path.lastIndexOf('/') + 1); downloadBook(in, fileName); } public static void downloadBook(InputStream in, String fileName) throws IOException { OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("/mnt/us/documents/", fileName))); try { byte[] b = new byte[4096]; int bytesRead; while ((bytesRead = in.read(b)) != -1) { out.write(b, 0, bytesRead); } } finally { in.close(); out.flush(); out.close(); } } }