bytereadtest.java

来自「java I/0流的代码程序」· Java 代码 · 共 28 行

JAVA
28
字号
import java.io.*;
class ByteReadTest
{
  public static void main(String argv[])
  {
    int b;
    byte buff[] = new byte[2500];
    try
    {
      FileInputStream readfile = new FileInputStream("aaa.txt");
      b = readfile.read(buff,0,2500);
      try
      {
        String str = new String(buff,0,b,"Default");
        System.out.println("读取内容为:"+str);
        System.out.println("字符串长度为:"+b+".");
        System.out.println("数组中位置为:"+0+"; ASCII码为:"+buff[0]+"; 对应字符为:"+"\""+(char)buff[0]+"\".");
        System.out.println("数组中位置为:"+(b-1)+"; ASCII码为:"+buff[b-1]+"; 对应字符为:"+"\""+(char)buff[b-1]+"\".");
        if(b%2==0) System.out.println("数组中位置为:"+(b/2)+"; ASCII码为:"+buff[b/2]+"; 对应字符为:"+"\""+(char)buff[b/2]+"\".");
        System.out.println("数组中位置为:"+b+"; ASCII码为:"+buff[b]+"; 对应字符为:"+"\""+(char)buff[b]+"\" .");
        System.out.println("数组中位置为:"+(b+1)+"; ASCII码为:"+buff[b+1]+"; 对应字符为:"+"\""+(char)buff[b+1]+"\".");
      }
      catch(UnsupportedEncodingException e1){}
    }
    catch(IOException e2){}
  }
}

⌨️ 快捷键说明

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