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

📄 usecharsets.java

📁 IBM JAVA NIO培训资料,有很好的实例
💻 JAVA
字号:
// $Id$import java.io.*;import java.nio.*;import java.nio.channels.*;import java.nio.charset.*;public class UseCharsets{  static public void main( String args[] ) throws Exception {    String inputFile = "samplein.txt";    String outputFile = "sampleout.txt";    RandomAccessFile inf = new RandomAccessFile( inputFile, "r" );    RandomAccessFile outf = new RandomAccessFile( outputFile, "rw" );    long inputLength = new File( inputFile ).length();    FileChannel inc = inf.getChannel();    FileChannel outc = outf.getChannel();    MappedByteBuffer inputData =      inc.map( FileChannel.MapMode.READ_ONLY, 0, inputLength );    Charset latin1 = Charset.forName( "ISO-8859-1" );    CharsetDecoder decoder = latin1.newDecoder();    CharsetEncoder encoder = latin1.newEncoder();    CharBuffer cb = decoder.decode( inputData );    // Process char data here    ByteBuffer outputData = encoder.encode( cb );    outc.write( outputData );    inf.close();    outf.close();  }}

⌨️ 快捷键说明

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