⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 16yuanmazhuanhuan.txt

📁 写的一个小工具
💻 TXT
字号:
写的一个小工具,用来将文件的内容显示为十六进制格式的字符,就像UE中的Ctrl+H功能。

Hextext.java

import java.io.*;

/**
 * Application: Hextext
 * Author: Steven
 * Data: April 18, 2007
 * Purpose:
Show file's content in hexadecimal text.

 * Usage:
Java Hextext filepath

 * Description:
The result file will be created in the same directory.
Its name is composed of source file name and ".hextest" as postfix.
 */
  


public class Hextext
{
    public static void main( String[] args ) throws Exception
    {
        // argument check
        if ( args.length < 1 )
        {
            println( "not enough arguments!" );
            printUsage();
        }
        if (!( new File( args[0] ).exists() ) )
        {
            println("assigned file doesnot exist!");
        }
        
        // parameters
        File srcfile = new File( args[0] );
        File destfile = new File( srcfile.getAbsolutePath() + ".hextext" );
        final int NUM_OF_CHAR_PER_LINE = 8;
        FileInputStream fin = new FileInputStream( srcfile );
        PrintWriter fout = new PrintWriter( new FileWriter( destfile ) );
        
        // transfer
        byte[] chunk = new byte[ NUM_OF_CHAR_PER_LINE ];
        int rdcnt = 0;
        
        
        while ( ( rdcnt = fin.read( chunk ) ) != -1 )
        {
            // init line buf
            char[] line_buf = new char[ NUM_OF_CHAR_PER_LINE * 3 + 1 + NUM_OF_CHAR_PER_LINE * 2 ];
            for ( int i=0; i<line_buf.length; ++i ) 
            { 
                line_buf[i] = ' '; 
                line_buf[ NUM_OF_CHAR_PER_LINE * 3 ] = '|';
            }
            // write into line buf
            for ( int i=0; i<rdcnt; ++i )
            {
                char[] hexd = toHextextByte( (int)chunk[i] ).toCharArray();
                line_buf[ i*3 ] = hexd[0];
                line_buf[ i*3+1 ] = hexd[1];
                line_buf[ NUM_OF_CHAR_PER_LINE * 3 + 1 + i*2 ] = (char)chunk[i];
            }
            // write line buf
            fout.println( line_buf );
        }
        
        fin.close();
        fout.close();
        
        // report
        println( "Transfer Successfully to File:" );
        println( destfile.getAbsolutePath() );
    }
    
    public static String toHextextByte( int nch )
    {
        String ret = Integer.toHexString( nch );
        int len = ret.length();
        if ( len == 1 )
        {
            ret = "0" + ret;
        }
        else if ( len > 2 )
        {
            ret = ret.substring( len-2 );
        }
        return ret;
    }
    
    public static void println( Object o )
    {
        System.out.println( o );
    }
    
    public static void printUsage()
    {
        println("Usage:");
        println("Hextext file_path");
        println("");
    }    
}/*END OF CLASS Hextext*/


⌨️ 快捷键说明

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