读取一个文本的指定字符,比如文本包括如下:
ese[int]=12345
ese[string]=who are you?
读取其中的类型名和值,分别显示.
//java读取文本文件
import java.io.*;
class 读文本指定内容
{
public static void main (String []args) throws Exception
{
File f = new File("f:/test.txt");
InputStreamReader read = new InputStreamReader (new FileInputStream(f),"GBK");
BufferedReader reader=new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null)
{
if(line.indexOf("[")!=-1)
{
int sstart=line.indexOf("[");
int send=line.indexOf("]");
int ss=line.indexOf("=");
String sstring=line.substring(sstart+1,send);
String sshuju=line.substring(ss+1);
System.out.println(sstring+" "+sshuju);
}
if(line.indexOf("$$$")!=-1)
{
line=reader.readLine();
System.out.println(line);
}
}
reader.close();
read.close();
}
}