fos = new FileOutputStream(file);
pw = new PrintWriter(fos);
pw.write(buf.toString().toCharArray());
pw.flush();
flag = true;
} catch (IOException e1) {
// TODO 自动生成 catch 块
throw e1;
} finally {
if (pw != null) {
pw.close();
}
if (fos != null) {
fos.close();
}
if (br != null) {
br.close();
}
if (isr != null) {
isr.close();
}
if (fis != null) {
fis.close();
}
}
return flag;
}
/**
* * Attempts to read a line of text from the input stream. Since a *
* telnet input stream always ends lines in CR/LF pairs, this method *
* returns all characters in the stream until a CR/LF pair or the *
* end-of-stream is reached. If no more bytes are available in the *
* stream, <code>null</code> is returned. * * @return A string
* representing the next line in the input stream. * @throws IOException If
* an I/O error occurs.
*/
public static String readLine(TelnetInputStream is) throws IOException {
int ch = is.read();
if (ch == -1)
return null;
StringBuffer buf = new StringBuffer(100);
buf.append((char) ch);
while (true) {
ch = is.read();
switch (ch) {
case 10:
return buf.toString();
// ch = is.read();
// switch (ch) {
//
// case '\n':
// return buf.toString();
// case '\0':
// buf.append('\r');
// break;
// case -1:
// throw new IOException("Unexpected end of " + "input");
// default:
// throw new IOException("Invalid char " + "after CR: "
// + ((char) ch));
//
// }
case -1:
return buf.toString();
default:
buf.append((char) ch);