溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時間:2021-01-13 11:33:54 來源:億速云 閱讀:203 作者:小新 欄目:軟件技術(shù)

這篇文章給大家分享的是有關(guān)如何使用Java程序代替Notepad++的文字處理和Powershell的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

由于Notepad++里面的文字處理有些復(fù)雜,我在想能不能用一個Java程序來統(tǒng)一處理呢?

嘗試了一下,發(fā)現(xiàn)不太復(fù)雜,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<String> aLink = new ArrayList<String>();
        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...");
    }
}

感謝各位的閱讀!關(guān)于“如何使用Java程序代替Notepad++的文字處理和Powershell”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI