如何用JAVA提取文本文档的多个数据(给分贴)

baohui54882 2008-11-06 11:35:44
这个帖子是给分的,因为一次只能给100分呵呵,分两个帖子给分
...全文
177 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanggc1001 2008-11-06
  • 打赏
  • 举报
回复
jf
rainsilence 2008-11-06
  • 打赏
  • 举报
回复
搞了半天是一个人。。。。
sunzhyng 2008-11-06
  • 打赏
  • 举报
回复
jf
hnjd314053754 2008-11-06
  • 打赏
  • 举报
回复

baohui54883 2008-11-06
  • 打赏
  • 举报
回复
不好意思,在另外一个帖子里已经有朋友帮助过我了,我想给他们200分,可我一个帖子只能给100分,所以我开了另外一个帖子给,所以请其他朋友不用回帖了~~
rainsilence 2008-11-06
  • 打赏
  • 举报
回复

import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;

import java.util.ArrayList;
import java.util.List;

public class LoggerReader {

private String content = null;

private List<String> ipList = new ArrayList<String>();

private List<String> osList = new ArrayList<String>();

private static final String INTERESTING_IP = "Interesting ports on ";

private static final String NO_OS_MATCH = "No OS matches for host";

private static final String OS_DETAIL = "OS details:";

public void readByteByFileStream(String url) {
try {
readByteByStream(new FileInputStream(url));
} catch(IOException e) {
e.printStackTrace();
}
}

public void readByteByStream(InputStream in) throws IOException {
byte[] b = new byte[in.available()];
in.read(b);
content = new String(b);
in.close();
}

public void toLogger() {
for (int i = 0; i < ipList.size(); i++) {
System.out.println("IP:" + ipList.get(i));
System.out.println("OS:" + osList.get(i));
}
}

public void parse() {
for (int index = 0; index < content.length() &&
content.indexOf(INTERESTING_IP, index) != -1; index++) {
int ipStartIndex = content.indexOf(INTERESTING_IP, index);
int ipEndIndex = content.indexOf(":", ipStartIndex + INTERESTING_IP.length());
ipList.add(content.substring(ipStartIndex + INTERESTING_IP.length(), ipEndIndex));
index = ipEndIndex;

int ipNextStartIndex = content.indexOf(INTERESTING_IP, index);
int osStartIndex = content.indexOf(OS_DETAIL, index);
if (osStartIndex > ipNextStartIndex || osStartIndex == -1) {
osList.add(NO_OS_MATCH);
} else {
int osEndIndex = content.indexOf(":", osStartIndex + OS_DETAIL.length());
osList.add(content.substring(osStartIndex + OS_DETAIL.length() + 1, osEndIndex));
}
}
}
public static void main(String[] args) {

LoggerReader reader = new LoggerReader();
reader.readByteByFileStream("e:\\a.txt");
reader.parse();
reader.toLogger();
}
}


a.txt
# Nmap 4.53 scan initiated Thu Nov 06 10:16:56 2008 as: nmap -sS -O -v -oN baohui 192.168.6.20-23
Initiating OS detection (try #1) against 3 hosts
Retrying OS detection (try #2) against 2 hosts
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=263 (Good luck!)
IP ID Sequence Generation: Incremental

Interesting ports on 192.168.6.22:
Not shown: 1709 closed ports
PORT STATE SERVICE
135/tcp open msrpc
139/tcp open netbios-ssn
445/tcp open microsoft-ds
990/tcp open ftps
1025/tcp open NFS-or-IIS
MAC Address: 00:1A:A0:3A:76:AC (Dell)
No OS matches for host
Network Distance: 1 hop

Interesting ports on 192.168.6.23:
Not shown: 1704 closed ports
PORT STATE SERVICE
21/tcp open ftp
80/tcp open http
135/tcp open msrpc
139/tcp open netbios-ssn
443/tcp open https
445/tcp open microsoft-ds
912/tcp open unknown
990/tcp open ftps
1025/tcp open NFS-or-IIS
1026/tcp open LSA-or-nterm
MAC Address: 00:1E:68:5C:19:E6 (Quanta Computer)
No OS matches for host
Network Distance: 1 hop

Read 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 10:17:13 2008 -- 4 IP addresses (3 hosts up) scanned in 16.938 seconds

这是刚才给一位朋友作的提取logger的方法
思路是首先得到流,然后组成String,最后用StringApi完成功能
pauliuyou 2008-11-06
  • 打赏
  • 举报
回复
啥意思?
tz_dzg 2008-11-06
  • 打赏
  • 举报
回复
多读几次啊,或者用多线程对多个不同文件并行读取
link_1029 2008-11-06
  • 打赏
  • 举报
回复
呵呵,客气了哦,希望能对你有所帮助.
baohui54882 2008-11-06
  • 打赏
  • 举报
回复
谢谢各位的帮助,我是新手,以后可能还会有问题请教大家
希望以后还能多多帮助小弟,再次谢过!
jianghuxiaoxiami 2008-11-06
  • 打赏
  • 举报
回复
楼主象征性的意思一下吧,浮云啊~~
忙碌的布谷鸟 2008-11-06
  • 打赏
  • 举报
回复
有意思。呵呵~
FAFA2008 2008-11-06
  • 打赏
  • 举报
回复
还是第一次见到如此慷慨的楼主
zhanggc1001 2008-11-06
  • 打赏
  • 举报
回复
我是来接分地!
lihan6415151528 2008-11-06
  • 打赏
  • 举报
回复
那就接分了!

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧