java获取txt文件内容属性值

有一个txt文件,内容如下:

     <room  height="9" width="6"/>

     <room  height="9" width="5"/>

     <room  height="9" width="5"/>

                    我要循环读取每行,并得到每行的height和width的值,求好代码,谢谢!

这种文件如果都是你这种固定格式,可以直接用XML解析的方式处理。如果只是简单的针对这个文件这种固定格式处理,用下面的代码足够了
[code="java"]import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class GetFileData {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    String path=System.getProperty("user.dir")+"\\data.txt";
    File data=new File(path);
    try {
        //用于逐行读取文件
        BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(data)));
        String line="";
        while(line!=null){
            line=reader.readLine();
            if(line!=null&&line.trim().length()!=0){
                //获得真正的文件内容
                //<room  height="9" width="6"/> 
                System.out.println(line);
                String[] temp=line.split("\"");

// for(String s:temp){
// System.out.println(s);
// }
System.out.println("height is:"+temp[1]);
System.out.println("width is:"+temp[3]);
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
[/code]

用js通过隐藏项传到后台

@Test
public void testPaterMacher(){
String intputstr = " ";
String regex = "\s*height=(\"\d\")\s*width=(\"\d\")";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(intputstr);
while(matcher.find()){
System.out.println("height=" + matcher.group(1));
System.out.println("width=" + matcher.group(2));
}

}