我正在研究一些与CSS类似的文件结构,但它与CSS有点不同
。 这里是用Java解析CSS文件
<ELEMENT NAME>{
Element attributes..1
Element attributes..2
Element attributes..3
}
我已经写了一个方法来获取元素名称
public String getElementName(File jSfile){
String elementName=null;
StringBuffer sb = null;
try{
BufferedReader br=new BufferedReader(new FileReader(jSfile));
String line=null;
while((line=br.readLine())!=null){
Pattern element=Pattern.compile("\\<(.+?)\\>",Pattern.DOTALL);
Matcher match=element.matcher(line);
match.find();
return match.group(1);
}
}
catch(Exception e){
return e.getLocalizedMessage();
}
return elementName;
}
而且使用这样的文件结构..
public static void main(String arg[]){
CSSReader cs=new CSSReader();
File f=new File("C:/Users/foo/bar/cascade.xyz");
String z=cs.getElementName(f);
System.out.print(z);
}
但它总是说'No match found'
编辑 我发现该文件包含多个具有不同名称的序列。 当我删除所有其他的,只保留一个代码的工作。
对不起,这里是菜鸟.....没有任何一个知道我会去MULTILINE ....感谢一吨 我要去哪里错了
没有,依然没有区别。 – lazyprogrammer
请参阅编辑..感谢 – lazyprogrammer