2012-02-08 31 views
1

我试图让仅从数据我从缓冲区读取我的数据的数据是这样的阅读服务名称,如何获得正确的输出放在我需要?我的逻辑线条文本分裂不好?

 
NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off 
acpid   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
anacron   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
apmd   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
atd    0:off 1:off 2:off 3:on 4:on 5:on 6:off 
auditd   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
autofs   0:off 1:off 2:off 3:on 4:on 5:on 6:off 
avahi-daemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off 
avahi-dnsconfd 0:off 1:off 2:off 3:off 4:off 5:off 6:off 
bluetooth  0:off 1:off 2:on 3:on 4:on 5:on 6:off 
capi   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
conman   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
cpuspeed  0:off 1:on 2:on 3:on 4:on 5:on 6:off 
crond   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
cups   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
daemon.sh  0:off 1:off 2:off 3:on 4:on 5:on 6:off 
dc_client  0:off 1:off 2:off 3:off 4:off 5:off 6:off 
dc_server  0:off 1:off 2:off 3:off 4:off 5:off 6:off 
dnsmasq   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
dund   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
firstboot  0:off 1:off 2:off 3:on 4:off 5:on 6:off 
gpm    0:off 1:off 2:on 3:on 4:on 5:on 6:off 
haldaemon  0:off 1:off 2:off 3:on 4:on 5:on 6:off 
hidd   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
hplip   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
httpd   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
ip6tables  0:off 1:off 2:on 3:on 4:on 5:on 6:off 
ipmi   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
iptables  0:off 1:off 2:on 3:on 4:on 5:on 6:off 
irda   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
irqbalance  0:off 1:off 2:on 3:on 4:on 5:on 6:off 
iscsi   0:off 1:off 2:off 3:on 4:on 5:on 6:off 
iscsid   0:off 1:off 2:off 3:on 4:on 5:on 6:off 
isdn   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
jexec   0:on 1:on 2:on 3:on 4:on 5:on 6:on 
kdump   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
kudzu   0:off 1:off 2:off 3:on 4:on 5:on 6:off 
libvirt-guests 0:off 1:off 2:off 3:on 4:on 5:on 6:off 
libvirtd  0:off 1:off 2:off 3:on 4:on 5:on 6:off 
lvm2-monitor 0:off 1:on 2:on 3:on 4:on 5:on 6:off 
mcstrans  0:off 1:off 2:on 3:on 4:on 5:on 6:off 
mdmonitor  0:off 1:off 2:on 3:on 4:on 5:on 6:off 
mdmpd   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
messagebus  0:off 1:off 2:off 3:on 4:on 5:on 6:off 
microcode_ctl 0:off 1:off 2:on 3:on 4:on 5:on 6:off 
multipathd  0:off 1:off 2:off 3:off 4:off 5:off 6:off 
netconsole  0:off 1:off 2:off 3:off 4:off 5:off 6:off 
netfs   0:off 1:off 2:off 3:on 4:on 5:on 6:off 
netplugd  0:off 1:off 2:off 3:off 4:off 5:off 6:off 
network   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
nfs    0:off 1:off 2:off 3:off 4:off 5:off 6:off 
nfslock   0:off 1:off 2:off 3:on 4:on 5:on 6:off 
nscd   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
ntpd   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
pand   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
pcscd   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
portmap   0:off 1:off 2:off 3:on 4:on 5:on 6:off 
psacct   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
rawdevices  0:off 1:off 2:off 3:on 4:on 5:on 6:off 
rdisc   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
readahead_early 0:off 1:off 2:on 3:on 4:on 5:on 6:off 
readahead_later 0:off 1:off 2:off 3:off 4:off 5:on 6:off 
restorecond  0:off 1:off 2:on 3:on 4:on 5:on 6:off 
rhnsd   0:off 1:off 2:off 3:on 4:on 5:on 6:off 
rhsmcertd  0:off 1:off 2:off 3:on 4:on 5:on 6:off 
rpcgssd   0:off 1:off 2:off 3:on 4:on 5:on 6:off 
rpcidmapd  0:off 1:off 2:off 3:on 4:on 5:on 6:off 
rpcsvcgssd  0:off 1:off 2:off 3:off 4:off 5:off 6:off 
saslauthd  0:off 1:off 2:off 3:off 4:off 5:off 6:off 
sendmail  0:off 1:off 2:on 3:on 4:on 5:on 6:off 
setroubleshoot 0:off 1:off 2:off 3:on 4:on 5:on 6:off 
smartd   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
squid   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
sshd   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
svnserve  0:off 1:off 2:off 3:off 4:off 5:off 6:off 
syslog   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
tux    0:off 1:off 2:off 3:off 4:off 5:off 6:off 
vncserver  0:off 1:off 2:off 3:off 4:off 5:off 6:off 
wdaemon   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
winbind   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
wpa_supplicant 0:off 1:off 2:off 3:off 4:off 5:off 6:off 
xend   0:off 1:off 2:on 3:on 4:on 5:on 6:off 
xendomains  0:off 1:off 2:off 3:on 4:on 5:on 6:off 
xfs    0:off 1:off 2:on 3:on 4:on 5:on 6:off 
xinetd   0:off 1:off 2:off 3:on 4:on 5:on 6:off 
ypbind   0:off 1:off 2:off 3:off 4:off 5:off 6:off 
yum-updatesd 0:off 1:off 2:on 3:on 4:on 5:on 6:off 

xinetd based services: 
     chargen-dgram: off 
     chargen-stream: off 
     cvs:   off 
     daytime-dgram: off 
     daytime-stream: off 
     discard-dgram: off 
     discard-stream: off 
     echo-dgram:  off 
     echo-stream: off 
     eklogin:  off 
     ekrb5-telnet: off 
     gssftp:   off 
     klogin:   off 
     krb5-telnet: off 
     kshell:   off 
     rmcp:   off 
     rsync:   off 
     tcpmux-server: off 
     tftp:   off 
     time-dgram:  off 
     time-stream: off 

我想从这个数据,这些都得到onlt役名实际上的服务我的Linux系统,我使用这种技术,

String text = ""; 
while((text = in.readLine()) != null) { 
    text = text.split(" ")[0];  
    services.append(text+"\n"); 
    System.out.print(text+"\n"); 
} 

其实我“在”使用缓冲区读写器读取数据缓冲区REDER,分裂它的空间,但我从该代码得到这个结果,

 
linuxNetworkManager 
acpid 
anacron 
apmd 
atd 
auditd 
autofs 
avahi-daemon 
avahi-dnsconfd 
bluetooth 
capi 
conman 
cpuspeed 
crond 
cups 
daemon.sh 
dc_client 
dc_server 
dnsmasq 
dund 
firstboot 
gpm 
haldaemon 
hidd 
hplip 
httpd 
ip6tables 
ipmi 
iptables 
irda 
irqbalance 
iscsi 
iscsid 
isdn 
jexec 
kdump 
kudzu 
libvirt-guests 
libvirtd 
lvm2-monitor 
mcstrans 
mdmonitor 
mdmpd 
messagebus 
microcode_ctl 
multipathd 
netconsole 
netfs 
netplugd 
network 
nfs 
nfslock 
nscd 
ntpd 
pand 
pcscd 
portmap 
psacct 
rawdevices 
rdisc 
readahead_early 0:off 1:off 2:on 3:on 4:on 5:on 6:off 
readahead_later 0:off 1:off 2:off 3:off 4:off 5:on 6:off 
restorecond 
rhnsd 
rhsmcertd 
rpcgssd 
rpcidmapd 
rpcsvcgssd 
saslauthd 
sendmail 
setroubleshoot 
smartd 
squid 
sshd 
svnserve 
syslog 
tux 
vncserver 
wdaemon 
winbind 
wpa_supplicant 
xend 
xendomains 
xfs 
xinetd 
ypbind 
yum-updatesd 

xinetd 
    chargen-dgram: 
    chargen-stream: off 
    cvs: 
    daytime-dgram: 
    daytime-stream: off 
    discard-dgram: 
    discard-stream: off 
    echo-dgram: 
    echo-stream: 
    eklogin: 
    ekrb5-telnet: 
    gssftp: 
    klogin: 
    krb5-telnet: 
    kshell: 
    rmcp: 
    rsync: 
    tcpmux-server: 
    tftp: 
    time-dgram: 
    time-stream: 

为什么有一些服务状态也与服务名称正在添加像

"readahead_early 0:off 1:off 2:on 3:on 4:on 5:on 6:off" 
"chargen-stream: off" 

我想所有这些服务的名称仅

+1

+1。欢迎来到SO! – 2012-02-08 06:54:19

回答

0

为什么不使用text.substring(0, text.indexOf(" ")); 基本上每行,从刚刚得到的一切第一个字符,直到第一个空格。

+0

通过使用此代码,它也打印所有状态与我不想要的服务名称:( – 2012-02-08 06:44:39

+0

写一些代码,以确定是否这些是服务名称后的制表符或空白?我怀疑有两种混合这种情况下分裂在空白ykaganovich建议。 – Ali 2012-02-08 06:47:56

+0

y它现在工作:) – 2012-02-08 08:04:22

2

也许你的来源是混合标签和空格?要么确保整个空间都被使用,要么对于一个结构良好的问题来说,要么是text.split("\\s+")

+0

它给错误不兼容的类型在你提到的这条线dabove – 2012-02-08 06:47:00

+1

我认为他的意思是'text.split(“\\ s +”)[0]' – 2012-02-08 06:56:08

+0

它帮助我:) – 2012-02-08 08:03:59

相关问题