我想用JAVA实现提取某个文本文件中的某行数据,
如提取出“OS details: Microsoft Windows XP SP2”,请问高手这个该怎么实现呢
文本内容如下# Nmap 4.53 scan initiated Thu Nov 06 08:52:28 2008 as: nmap -sS -O -v -oN baohui 192.168.6.21 
Initiating OS detection (try #1) against 192.168.6.21
Interesting ports on 192.168.6.21:
Not shown: 1709 filtered ports
PORT     STATE SERVICE
80/tcp   open  http
139/tcp  open  netbios-ssn
443/tcp  open  https
445/tcp  open  microsoft-ds
3389/tcp open  ms-term-serv
MAC Address: 00:1B:B9:85:FE:95 (Elitegroup Computer System Co.)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose
Running: Microsoft Windows XP
OS details: Microsoft Windows XP SP2
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=260 (Good luck!)
IP ID Sequence Generation: IncrementalRead data files from: E:\nmap-4.53
OS detection performed. Please report any incorrect results at http://insecure.org/nmap/submit/ .
# Nmap done at Thu Nov 06 08:52:38 2008 -- 1 IP address (1 host up) scanned in 10.391 seconds

解决方案 »

  1.   

    用BufferedReader逐行读取,然后用equals判断是否是你想要的
      

  2.   

    如果LZ文本格式是死的话,最土的方法是循环到你想你想读取的行,直接读.....
    建议将文本修改为Properties格式的文件.名值对应.可以解决LZ的问题
      

  3.   

    inipath是文件路径,string型
    FileReader ini = new FileReader(inipath);
    BufferedReader iniparameter = new BufferedReader(ini);
    iniparameter.skip(10);//跳过多少个字符
    mdbUrl = iniparameter.readLine();
      

  4.   


    public class TTTT { public static String getString(String filename) throws IOException {
    StringBuffer sb = new StringBuffer();
    BufferedReader r = null; r = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "utf-8"));
    String s = null;
    while ((s = r.readLine()) != null) {
    if(s.startsWith("OS details:"))
    break;
    }
    r.close();
    return s;
    } public static void main(String[] args) throws IOException {
    String s = getString("tt.txt");
    System.out.println(s); }
    }