欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Java 测试文件指针,java测试指针,两种方法打开文件并进行内

来源: javaer 分享于  点击 130 次 点评:244

Java 测试文件指针,java测试指针,两种方法打开文件并进行内


两种方法打开文件并进行内容定位

package com.ronsoft.books.nio.channels;import java.nio.channels.FileChannel;import java.io.RandomAccessFile;import java.io.IOException;/** * Test file pointer manipulation between FileChannel and RandomAccessFile * objects. * * Created Feb 2002 * @author Ron Hitchens (ron@ronsoft.com) * @version $Id: FilePointer.java,v 1.1 2002/02/20 03:16:33 ron Exp $ */public class FilePointer{   public static void main (String [] argv)      throws IOException   {      RandomAccessFile randomAccessFile = new RandomAccessFile (argv [0], "r");      randomAccessFile.seek (1000);      FileChannel fileChannel = randomAccessFile.getChannel();      // This will print "1000"      System.out.println ("file pos: " + fileChannel.position());      randomAccessFile.seek (500);      // This will print "500"      System.out.println ("file pos: " + fileChannel.position());      fileChannel.position (200);      // This will print "200"      System.out.println ("file pos: " + randomAccessFile.getFilePointer());   }}//该片段来自于http://byrx.net
相关栏目:

用户点评