使用java读取linux配置文件 [英] read linux config files using java
问题描述
嗨我需要一些帮助,在我的项目中使用java中的构建应用程序从Linux系统读取配置文件,我不会从这个文件中显示一些这样的值
//配置文件中的代码
子网192.168.1.0网络掩码255.255.255.0 {
范围192.168.1.128 192.168.1.254;
option subnet-mask 255.255.255.0;
选项广播地址192.168.1.255; #commnet这里
....
}
在应用程序中播种它应该打印类似的东西
网络1:192.168.1.0/24
范围:从192.168 .1.128到192.168.1.254
面具:255.255.255.0
广播:192.168.1.255
所以我需要从指定的args读取值,如option subnet-mask到行的末尾是;并返回值255.255.255.0。如果有评论#不做任何事情只需转到下一行。并且对于每个配置从{开始并以}结束。所以当凸轮到}时应该停止。然后去那里的下一个网络。感谢帮助
用Java读取文件并解析字符串相对容易。请参阅 http://docs.oracle.com/javase/tutorial/essential/io/index.html [ ^ ]和 http://docs.oracle.com/javase/tutorial/java/data/index.html [ ^ ]
hi i need some help in my project a build application in java that read config files from Linux system and i wont to show some value from this files like this
//the code in config file subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.128 192.168.1.254; option subnet-mask 255.255.255.0; option broadcast-address 192.168.1.255;#commnet here .... }
sow in the application it should be print something like that
network 1 : 192.168.1.0/24 range : from 192.168.1.128 to 192.168.1.254 mask : 255.255.255.0 broadcast : 192.168.1.255
so i need to read the value from specified args like "option subnet-mask" to the end of the line is ";" and return just the value "255.255.255.0". and if there comment "#" don't do anything just go to next line. and for each configuration is start from "{" and end at "}". so when is cam to "}" is should be stopped. and go for the next network if there. thanks for helping
Reading files in Java and parsing strings is relatively easy. See http://docs.oracle.com/javase/tutorial/essential/io/index.html[^] and http://docs.oracle.com/javase/tutorial/java/data/index.html[^].
这篇关于使用java读取linux配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!