])\\\\s*>”; Pattern pattern=pattern.compile(patternString,patten.CASE_INSENSITIVE); While(matcher.find( )) { Int start=matcher.stat( ); Int end=matcher.end( );Stromg match = input.substring(start,end); System.out.println(match); } }
catch(IOException exception) { Exception.printlStackTace( ); }
catch (PatternSyntaxException exception) { Exception.printlSackTace( ); } } }
2 本程序的功能是将一个工资表.dat文件以字符流的方式写入读出。这里的.dat文件是一个带有分隔符记录的Unicode码。请在下划线处,填入适当语句完成此程序。 import java.io.*; import java.util.*;
public class DataFileTest {
public satic void main (String[] args) { Employee[ ] staff = new Employee[3];
Staff[0] = new Employee(“Carl Cracker”,75000,1987,12,15); Staff[1] = new Employee(“Harry Hacker”,50000,19,10,1); Staff[2] = new Employee(“Tony Tester”,40000,1990,3,15); try {
PrintWriter out =new printWriter(new FileWriter(“employy.dat”); writeData(staff,out); out.close( );
BufferedReader in= new BufferedReader(new FileReader(“employee.dat”)); Employee[ ] newStaff = readData(in); In.close( );
For(int i=0;iCatch(IOException exception) { exceptionprintlStackTrace( ); } }Static void writeData(Employee[] e,printWriter out)throws IOException {
out.println(e.length); for(int i=0;iStatic Employee[] readData(BufferedReader in)throws IOEception { int n=Integer.parseInt(in.readLine( )); Employee[]e= new Empolyee[n]; for(int i=0; iE[i] = new Employee( ); } return e; } }3 请编写用RandomAccessFile oureFile; String s=“information to Append \\ n mon!\\n\\”;
oureFile = new RandomAccessFile oureFile(“phone.nember.numbers”,“rw”);模式打开访问oureFile文件,并在
文件尾加s的addFile程序。