how to put things into the database cache , find the code .
------ Solution ---------------------------------------- ----
application ? Have written records on the console to the text, read text directly into a field won. But I can not think of what role
------ Solution -------------------------------- ------------
------ Solution ------------------------------------ --------
synchronized (this) {
try {
out.print (cmd);
out.flush ();
System.out.println (" sent :" + cmd);
while ((readed = in.readLine ())! = null) {
System.out.println (" received :" + readed);
readedsb = readedsb.append (readed + "/ r / n");
}
} catch (SocketTimeoutException e) {
System.out.println (" Receive: Timeout ! " ) ; / / Ignore this exception
} catch (IOException e) {
throw new TelnetException (e);
}
}
------ For reference only --------------------------------- ------
I've been able to achieve telnet , but just do not know how to display the information stored in the database . Solution.
------ For reference only -------------------------------------- -
now I can output the screen can be , but you want to save to the database, a little bit of trouble.
public String readUntil(String pattern) {
try {
char lastChar = pattern.charAt(pattern.length() - 1);
StringBuffer sb = new StringBuffer();
char ch = (char)in.read();
while (true) {
sb.append(ch);
if (ch == lastChar) {
if (sb.toString().endsWith(pattern)) {
return sb.toString();
}
}
if(ch==(char)13)
{
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
Date now = new Date();
String sysdate = df.format( now );
String st = sb.toString();
if(st.length()>0)
{
String st2=st;
}
System.out.println("+++++++"+st+"======"+sysdate);
}
ch = (char)in.read();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
没有评论:
发表评论