public class t10_6s {
DatagramSocket dsock = null;
DatagramPacket inp;
DatagramPacket outp;
byte[] inbuff=new byte[100];
byte[] outbuff;
PrintWriter pw;
String s,s1;
public t10_6s(){
try {
dsock=new DatagramSocket (8000);
pw=new PrintWriter(new FileWriter("test_6.txt"));
while(true){
inp=new DatagramPacket(inbuff,inbuff.length );
dsock.receive(inp);
s=new String(inp.getData(),0,inp.getLength());
System.out.println(":"+s);
pw.print( s);
}
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
finally{pw.close();}
}
public static void main(String[] args) {
new t10_6s();
}
}
问题:当程序关闭是怎样把文件流(pw)关闭!!!