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


本文摘自PHP中文网,作者藏色散人,侵删。

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

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

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

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...");

    }

}

更多notepad教程,请访问notepad使用教程栏目:https://www.php.cn/tool/notepad/

以上就是用Java程序代替Notepad++的文字处理和Powershell的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

ise怎么调用Notepad

ise如何关联Notepad++

Notepad怎么对齐

Notepad如何调成中文版

如何使用Notepad打开二进制文件格式

Notepad怎么调中文版

Notepad怎么换行

Notepad怎么改中文?

技巧分享:Notepad在每行首尾怎么添加内容

Notepad怎么看文件的编码格式

更多相关阅读请进入《Notepad》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...