gb2big5.java

来自「这个程序实现了在网络上截获邮件数据并还原邮件。仅供学习参考」· Java 代码 · 共 60 行

JAVA
60
字号
import java.io.*;
import java.util.*;

public class gb2big5 
  {
    static int iCharNum=0;
    public static void main(String[] args) 
      {
        System.out.println("Input GB2312 file, output Big5 file.");
        if (args.length!=2) //判断是否输入了两个参数
		  {  
            System.err.println("请在命令行后添加输入及输出文件参数! \n   如:java gb2big5 gb.txt big.txt");
            System.exit(1);
	      }

        String inputString = readInput(args[0]);
        writeOutput(inputString,args[1]);
        System.out.println("Number of Characters in file: "+iCharNum+".");

      }

    static void writeOutput(String str, String strOutFile) 
	  {
        try{
          FileOutputStream fos = new FileOutputStream(strOutFile);
          Writer out = new OutputStreamWriter(fos, "big5");
          out.write(str);
          out.close();
           }
        catch (IOException e) {
          e.printStackTrace();
          e.printStackTrace();
          }
      }

    static String readInput(String strInFile)
	  {
        StringBuffer buffer = new StringBuffer();
        try{
          FileInputStream fis = new FileInputStream(strInFile);
          InputStreamReader isr = new InputStreamReader(fis, "gb2312");
          Reader in = new BufferedReader(isr);
          int ch;
		  
          while ((ch = in.read()) > -1) 
		    {
			  iCharNum += 1;
              buffer.append((char)ch);
            }
          in.close();
          return buffer.toString();
      }
        catch (IOException e) {
          e.printStackTrace();
          return null;
          }
      }
  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?