My problem:我需要从一个文本文件中获取几个值。
我正在开发一个解析器,从ttcn-3语言到XML语言,我需要做的是从ttcn模块中获取一些关键字和值,ttcn模块是用文本文件来构建XML文件的。
这里是我的ttcn代码的开始:
module SessionSetup
{
type port InputPortType message { in charstring }
type port OutputPortType message { out charstring }
type component SessionSetupResComponentType {
port InputPortType InputPort;
port OutputPortType OutputPort;
}例如,我需要得到紧跟在模块(SessionSetup)之后的字符串,下面是我编写的代码:
public void ReadTheFileGetTheModuleName(String fichier){
try{
InputStream ips=new FileInputStream(fichier);
InputStreamReader ipsr=new InputStreamReader(ips);
BufferedReader br=new BufferedReader(ipsr);
String ligne;
while ((ligne=br.readLine())!=null){
if (ligne.contains("module"))
{
String[] st = ligne.split(ligne, ' ');
System.out.println("Nom = "+st[1]);
}
chaine+=ligne+"\n";
}
br.close();
}
catch (Exception e){
System.out.println(e.toString());
}
}问题是,它不工作,我没有得到一个接一个模块字符串。
谢谢
发布于 2015-03-18 13:12:01
String[] st = ligne.split(ligne, ' ');
/\/\/\/\/\/\/\
Incorrect way, pass some regex on which string should split您的String#Split()方法出错,请检查文档
应该是这样的
public String[] split(String regex, int limit)
or
public String[] split(String regex)注意:您不会得到编译时错误,因为split()方法中的(‘')是一个字符,可以隐式类型为Integer。
https://stackoverflow.com/questions/29122967
复制相似问题