String[] gettxt=new String[255];
int filepointer,filesize,num = 0;
try
    { 
          fff =new RandomAccessFile(fn,action);
  filesize = fff.length();
  System.out.println("File size :"+ filesize);
  while ( filesize > filepointer)
  {
     filepointer = fff.getFilePointer();
     gettxt[num] = fff.readLine();
     System.out.println("filepointer : "+filepointer+"  "+sss);
     num = num + 1;
  }
  fff.close(); 
    }
    catch(FileNotFoundException dd)
    {
      System.out.println("no file");
    }
    catch(IOException s)
    {
      System.out.println("read file error");
    }
    
    

解决方案 »

  1.   

    你写的和我的好像是一样的,我上面那个类是没错的了,但如何调用呢,它返回一个数组,那我要如何用呢
    readtxt myread=new readtxt();
    myread.getfiletxt("d:\\a.txt");就在这返回的是一个数组了,这里开始要如何做了呢
      

  2.   

    readtxt myread=new readtxt();
    String[] toUse=myread.getfiletxt("d:\\a.txt");
    //例子
    for(int i=0;i<toUse.length;i++){
    System.out.println(toUse[i]);
    }
      

  3.   

    ycats(加菲猫) 帮我看看,等会来加分,我现在出去
    D:\Work>javac readtxtservlet.java
    readtxtservlet.java:26: 不兼容的类型
    发现:java.lang.String
    需要:java.lang.String[]
                                    String[] toUse=myread.getfiletxt("d:\\a.txt");
                                                                    ^
      

  4.   

    //此处
    while(file.getFilePointer<file.length())
    //应为
    while(file.getFilePointer()<file.length())
    //另外读文本结束判断有问题(虽然不报错)
    //请注意JAVA的规范。类名用大写开头!
      

  5.   

    Try this:
    ____________________________________________________________________________
    import java.io.*;
    public class readtxt
    {
    String getfilepath;
      public readtxt(String strFileName)
      {
       getfilepath = strFileName;
      }
      
      public String[] getfiletxt()
    {
       if (getfilepath==null) return new String[]{""};
      
       File fn=new File(getfilepath);
       String[] gettxt = new String[255];
       int i=0;
       if(fn.isFile()&&fn.canRead())
    {
       try
    {
          RandomAccessFile file=new RandomAccessFile(fn,"r");
    while(file.getFilePointer() < file.length())
    {
    gettxt[i]=file.readLine();
    i=i+1;
    }
    file.close();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    return gettxt; 
    }

    public static void main(String args[])
    {
    if(args.length < 1)
    {
    System.out.println("Please input the file name.");
    System.exit(0);
    }
    readtxt oGetFileTxt = new readtxt(args[0]);
    String[] strArrayGetFileTxt =  oGetFileTxt.getfiletxt();
    System.out.println("strArrayFileTxt[0] = " + strArrayGetFileTxt[0]);
    System.out.println("strArrayFileTxt[1] = " + strArrayGetFileTxt[1]);
    }
    }
    _____________________________________________________________________________
      

  6.   

    请再帮我看看,编译说没有返回结果package gw;
    import java.io.*;
    public class readtxt
    {
       public  String[] getfiletxt(String getfilepath)
    {
       try
    {
       if (getfilepath==null) return new String[]{""};
       File fn=new File(getfilepath);
       String[] gettxt=new String[255];
       int i=0;
       if(fn.isFile()&&fn.canRead())
    {
       
                           RandomAccessFile file=new RandomAccessFile(fn,"r");

        while(file.getFilePointer()<file.length())
    {

    gettxt[i]=file.readLine();
    i=i+1;
    }
    file.close();
    return gettxt;

    }
    }
    catch(Exception e)
    {
    e.printStackTrace();

    }

    } }
      

  7.   

    哦,你在最后
    catch(Exception e)
    {
    e.printStackTrace();}
    应该返回

    catch(Exception e)
    {
    e.printStackTrace();
    return null;
    }
      

  8.   

    sorry for just took a mistake
    看下面的代码://注释所说
    if (fn.isFile() && fn.canRead())
    { RandomAccessFile file = new RandomAccessFile(fn, "r");
               while (file.getFilePointer() < file.length())
    {
    gettxt[i] = file.readLine();
    i = i + 1;
    }
    file.close();
    return gettxt;
    }
    //here should return
    }
    catch (Exception e)
    {
       e.printStackTrace();
        //here should return  
    }
      

  9.   

    现在编译通过了,public static String Fmt_Value(double Value)throws Exception和
    public  String Fmt_Value(double Value)throws Exception有什么区别呢,static主要作用是什么,: ycats(加菲猫) 帮我答,我马上加分了,谢谢
      

  10.   

    静态变量(方法)不需实例可以调用
    如:public static String Fmt_Value(double Value)throws Exception
        可以:ClassName.Fmt_Value(double Value)
        public  String Fmt_Value(double Value)throws Exception
        必须:
             new ClassName().Fmt_Value(double Value)
    请看看Java的基本书籍