public static void main(String[] args){
BufferedReader br = null;
try {
br = new BufferedReader(
new InputStreamReader(
new FileInputStream("一个txt文件")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
String[] appName;
int lineNo = 1;
while (line != null) {
appName = line.split("\\[");
String[] APP;
String app = appName.toString();
if(appName != null) {
APP = app.split("\\]");
System.out.println("Line" + lineNo + " " + APP[0]);
lineNo ++;
}
try {
line = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
txt文件里面是:
我爱[慕]课网
我爱j[ava]
我[爱]编程
运行结果是:
Line1 [Ljava.lang.String;@3cd1a2f1
Line2 [Ljava.lang.String;@2f0e140b
Line3 [Ljava.lang.String;@7440e464
求各路大神解答,拜托了!
winter_yi
管理員
相关分类