1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 离线保存浏览器网页

离线保存浏览器网页

时间:2020-06-21 20:57:27

相关推荐

离线保存浏览器网页

--离线保存浏览器网页

1.fiddler 开启,google 浏览器访问 ,将地址拷贝下来

3.java saving 保存图片

package c;import java.io.BufferedReader;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.io.InputStreamReader;import .HttpURLConnection;import .URL;public class test {public static void main(String argv[]) {String filePath = "C:\\Users\\Administrator\\Desktop\\feed.txt";// String filePath = "C:\\Users\\Administrator\\Desktop\\error.txt";readTxtFile(filePath);}/*** 功能:Java读取txt文件的内容 步骤:1:先获得文件句柄 2:获得文件句柄当做是输入一个字节码流,需要对这个输入流进行读取* 3:读取到输入流后,需要读取生成字节流 4:一行一行的输出。readline()。 备注:需要考虑的是异常情况* * @param filePath*/public static void readTxtFile(String filePath) {try {String encoding = "GBK";File file = new File(filePath);if (file.isFile() && file.exists()) { // 判断文件是否存在InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);// 考虑到编码格式BufferedReader bufferedReader = new BufferedReader(read);String lineTxt = null;String tmp = "";while ((lineTxt = bufferedReader.readLine()) != null) {doline(lineTxt);}read.close();} else {System.out.println("找不到指定的文件");}} catch (Exception e) {System.out.println("读取文件内容出错");e.printStackTrace();}}public static void doline(String str) {try {String savepath = "C:\\Users\\Administrator\\Desktop\\";String home = "/";String name = str.replace(home, "");String tmp = name;if (!tmp.contains(".")) {// 当前处于htmlSystem.out.println("html:" + str);} else {tmp = savepath + tmp;// 3cengtmp = tmp.substring(0, tmp.lastIndexOf("/"));String last = tmp;String lastone = last;if (last.contains("/")) {try {last = last.substring(0, last.lastIndexOf("/"));} catch (Exception e) {// System.out.println("-----------");}lastone = last;try {lastone = lastone.substring(0, lastone.lastIndexOf("/"));} catch (Exception e) {// System.out.println("-----------");}}if (!new File(lastone).isDirectory()) {new File(lastone).mkdir();}if (!new File(last).isDirectory()) {new File(last).mkdir();}if (!new File(tmp).isDirectory()) {new File(tmp).mkdir();}System.out.println("..."+name);sendImageFile(home + name, savepath + "" + name);}} catch (Exception e) {System.out.println("test.doline()" + str);e.printStackTrace();}}public static void deal(String url, String path) {String tmp = path;tmp = tmp.substring(0, tmp.lastIndexOf("/"));String last = tmp;tmp = tmp.substring(0, tmp.lastIndexOf("/"));if (!new File(tmp).isDirectory()) {new File(tmp).mkdir();}if (!new File(last).isDirectory()) {new File(last).mkdir();}sendImageFile(url, path);System.out.print("finsh.." + url);}private static String sendImageFile(String url, String path) {String subUrl = "";// System.out.println("test.sendImageFile()"+url+"\t"+path);try {URL url2 = new URL(url);// Log.i("http:send", "http send"+url);HttpURLConnection httpUrl = (HttpURLConnection) url2.openConnection();// 设置通用的请求属性httpUrl.setRequestProperty("accept", "*/*");httpUrl.setRequestProperty("connection", "Keep-Alive");httpUrl.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;SV1)");// httpUrl.setRequestProperty("Content-type", "application/text");httpUrl.setRequestProperty("Content-Type", "image/*");// 连接指定的网络资源httpUrl.connect();InputStream inStream = httpUrl.getInputStream();ByteArrayOutputStream outStream = new ByteArrayOutputStream();byte[] buffer = new byte[4*1024];int len = 0;while ((len = inStream.read(buffer)) != -1) {outStream.write(buffer, 0, len);}inStream.close();writeImageToDisk(outStream.toByteArray(), path);} catch (Exception e) {e.printStackTrace();}// System.out.println();return subUrl;}/*** 将图片写入到磁盘* * @param img* 图片数据流* @param fileName* 文件保存时的名称*/public static void writeImageToDisk(byte[] img, String fileName)throws Exception {File file = new File("" + fileName);FileOutputStream fops = new FileOutputStream(file);fops.write(img);fops.flush();fops.close();}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。