好久没有写博客了,最近有点忙........ 废话不说,直接说所要实现的功能。
需要从linux服务器上读取文件夹,知道该文件夹有没有新的文件产生,后期还需要发送到其他平台上(发送其他平台就不说了)
思路:开始我想使用监听器呢,但是要求不能使用监听器,所以就放弃了, 我直接读取新产生的文件,使用linux脚本
依赖如下:
ch.ethz.ganymed
ganymed-ssh2
build210
private ListlinuxUtils(String record) { List file = new ArrayList<>(); Connection conn = new Connection(host, port);//host:是服务器的地址 try { // 启动连接 conn.connect(); conn.authenticateWithPassword(user, pswd); Session session = conn.openSession(); session.getStdout(); session.execCommand(record); InputStream stdout = new StreamGobbler(session.getStdout()); BufferedReader br = new BufferedReader(new InputStreamReader(stdout)); while (true) { String line = br.readLine(); if (line == null) break; file.add(line); } conn.close(); session.close(); } catch (IOException e) { e.printStackTrace(); } return file; }



