例如我的txt文件是okokokokokokbegin123213okok12412551endokok我想读入从begin开始的数字和字符然后到end结束我已经会读入txt的程序如何修改才行publicstaticvoidmain(String[]args)...
例如我的txt文件是 okokokokokokbegin123213okok12412551endokok
我想读入从begin开始的数字和字符 然后到end 结束 我已经会读入txt的程序 如何修改才行
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("C:/zc.txt");
BufferedReader
reader = null;
String tempString = null;
int line =1;
try
{
System.out.println("以行为单位读取文件内容,一次读一整行:");
reader = new BufferedReader(new
FileReader(file));
while ((tempString =
reader.readLine()) != null) {
System.out.println("Line"+ line + ":"
+tempString);
line
++ ;
}
reader.close();
} catch
(FileNotFoundException e) {
// TODO
Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch
block
e.printStackTrace();
}finally{
if(reader != null){
try {
reader.close();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
展开