StringBuffer result = new StringBuffer(); 
try
        {
            InputStreamReader = new InputStreamReader(new FileInputStream(resource),encode);
    int ch;
            while ((ch = isr.read()) > -1)
            {
                result.append((char)ch);
            }
    isr.close();
        } catch(IOException e) {
            Log.getInstance(ReadFile.class).error("Can not open file!",e);
            return false;
        }
System.out.print(result.toString());

解决方案 »

  1.   

    谢谢!请问几个问题!!!,
    1,resource ,encode指什么???
    2,(ch = isr.read()) > -1又指什么???
      

  2.   

    不过搂主,好像你可以直接在UltraEdit, 或者EditPlus里手工按块copy出来吧。不过如果硬是要用代码,可以这样读出来:import java.io.BufferedReader;
    import java.io.FileReader;public class Test2 {    final static int START_POSITION = 5; // phone start position    public static void main(String[] args) throws Exception {
            StringBuffer result = new StringBuffer();
            BufferedReader bw = new BufferedReader(new FileReader("test.txt"));
            String line;
            while ((line = bw.readLine()) != null) {
                String phoneNo = line.substring(START_POSITION, START_POSITION + 11);
                System.out.println(phoneNo); // or output to another file
            }
            bw.close();
            System.out.print(result.toString());
        }
    }
      

  3.   

    import java.io.BufferedReader;
    import java.io.FileReader;public class Test {//    final static int START_POSITION = 5; // phone start position    public static void main(String[] args) throws Exception {
            StringBuffer result = new StringBuffer();
            BufferedReader bw = new BufferedReader(new FileReader("test.txt"));
            String line;
            int index;
            while ((line = bw.readLine()) != null) {
             index = line.indexOf(" ");  //与文件中的空格数要一样
                String phoneNo = line.substring(index, index + 11);
                System.out.println(phoneNo); // or output to another file
            }
            bw.close();
            System.out.print(result.toString());
        }
    }这样,不论前边的字段怎么变化都能取出!!!