隨筆-153  評(píng)論-235  文章-19  trackbacks-0

          ?



          import ?java.io.File;
          import ?java.io.FileInputStream;
          import ?java.io.FileNotFoundException;
          import ?java.io.IOException;
          import ?java.nio.ByteBuffer;
          import ?java.nio.channels.FileChannel;


          public ? class ?ReadAString? {

          ????
          /**
          ?????*?
          @param ?args
          ?????
          */

          ????
          public ? static ? void ?main(String[]?args)? {
          ????????
          // ?TODO?自動(dòng)生成方法存根

          ????????File?aFile?
          = ? new ?File( " d:/test.txt " );
          ????????FileInputStream?inFile?
          = ? null ;
          ????????
          ????????
          try ? {
          ????????????inFile?
          = ? new ?FileInputStream(aFile);
          ????????}
          ? catch (FileNotFoundException?e)? {
          ????????????e.printStackTrace(System.err);
          ????????????System.exit(
          1 );
          ????????}

          ????????
          ????????FileChannel?inChannel?
          = ?inFile.getChannel();
          ????????ByteBuffer?buf?
          = ?ByteBuffer.allocate( 48 );
          ????????
          // String?buf?=?"";
          ???????? try ? {
          ????????????
          while (inChannel.read(buf)? != ? - 1 )? {
          ????????????????System.out.println(
          " String?read:? " +
          ????????????????????????((ByteBuffer)(buf.flip())).asCharBuffer().toString());
          ????????????????buf.clear();
          ????????????}

          ????????????System.out.println(
          " EOF?readched. " );
          ????????????inFile.close();
          ????????}
          ? catch (IOException?e)? {
          ????????????e.printStackTrace(System.err);
          ????????????System.exit(
          1 );
          ????????}

          ????????
          ????????System.exit(
          0 );
          ????}


          }

          posted on 2006-11-11 15:40 流浪汗 閱讀(379) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Java
          主站蜘蛛池模板: 巧家县| 宣城市| 孝昌县| 庆阳市| 保靖县| 舒城县| 舟山市| 铜鼓县| 香格里拉县| 财经| 绥宁县| 承德市| 明溪县| 渑池县| 灵山县| 尤溪县| 沁水县| 洞口县| 准格尔旗| 三明市| 莫力| 韶关市| 清水河县| 民乐县| 新兴县| 新干县| 密云县| 思南县| 玉门市| 金坛市| 祁连县| 瓦房店市| 巴马| 新和县| 宿州市| 景洪市| 盱眙县| 三穗县| 江城| 滦平县| 安达市|