快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

如何使用Java程序代替Notepad++的文字处理和Powershell

这篇文章给大家分享的是有关如何使用Java程序代替Notepad++的文字处理和Powershell的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

创新互联公司于2013年创立,先为达州等服务建站,达州等地企业,进行企业商务咨询服务。为达州企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

由于Notepad++里面的文字处理有些复杂,我在想能不能用一个Java程序来统一处理呢?

尝试了一下,发现不太复杂,Java果然处理各种事情都比较方便。程序如下:

注意在RegExp里面,必须用四个反斜杠\\\\代表一个反斜杠\

package com.pwc;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WechatMomentDownload {
    
    public static String jsonFile = "C:\\Download\\exported_sns_gary.json";
    public static String outputFolder = "C:\\Download\\gary_pic\\";
    public static void main(String[] args) throws IOException {
        BufferedReader reader = null;
        String sLine = "";
        String sContent = "";
        String sLink = "";
        URL url = null;
        String outputFile = "";
        ArrayList aLink = new ArrayList();
        String Regex1 = "CDATA\\[http\\:\\\\\\/\\\\\\/(sh)?mmsns([^]]*)\\/0\\]";
        
        reader = new BufferedReader(
                new InputStreamReader(new FileInputStream(new File(jsonFile)), "UTF-8"));
        if (reader != null) {
            while ((sLine = reader.readLine()) != null) {
                sContent = sContent + sLine;
            }
            reader.close();
        }
        
        Pattern pattern = Pattern.compile(Regex1);
        Matcher matcher = pattern.matcher(sContent);
        int count = 0;
        
        System.out.println("Start processing...");
        while(matcher.find()) {
            count++;
            sLink = sContent.substring(matcher.start() + 6, matcher.end() - 1);
            sLink = sLink.replaceAll("\\\\/", "/");
            aLink.add(sLink);
         }
        
        System.out.println(count + " pictures were found");
        
        for (String sLinkTemp : aLink) {
            url = new URL(sLinkTemp);
            DataInputStream dataInputStream = new DataInputStream(url.openStream());
            
            outputFile = outputFolder + count + ".jpg";
            FileOutputStream fileOutputStream = new FileOutputStream(new File(outputFile));
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            System.out.println("Downloading " + sLinkTemp + " to file " + outputFile);
            
            byte[] buffer = new byte[1024];
            int length;
 
            while ((length = dataInputStream.read(buffer)) > 0) {
                output.write(buffer, 0, length);
            }
            fileOutputStream.write(output.toByteArray());
            dataInputStream.close();
            fileOutputStream.close();
        
            count--;
        }
        
        System.out.println("End of processing...");
    }
}

感谢各位的阅读!关于“如何使用Java程序代替Notepad++的文字处理和Powershell”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!


标题名称:如何使用Java程序代替Notepad++的文字处理和Powershell
文章路径:http://6mz.cn/article/jpghoo.html

其他资讯