私は、CSS に似たファイル構造を含むものに取り組んでいますが、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'
編集ファイルには、名前が異なる複数のシーケンスが含まれていることがわかりました。他のすべてのものを削除し、1 つだけを保持すると、コードは機能しました。
ここで初心者になって申し訳ありません.....マルチラインについて私がどのように行くか知っている人はいますか....トンに感謝しますどこが間違っているのですか