// String ls = instance.execCmd("top -p 21475 -n 1 -b"); String ls = instance.execCmd("sh /home/hadoop/project/flume-hdfs.sh start"); List<String> lineFreedList = StrSplitter.splitByRegex(StrUtil.trimToEmpty(ls), "\n", -1, true, true); for (String s : lineFreedList) { List<String> stringList = StrSplitter.split(StrUtil.trimToEmpty(s), "=", -1, true, true); System.out.println(stringList);
时间: 2024-04-05 07:34:38 浏览: 20
这是一段Java代码,使用了一个名为"instance"的对象来执行两个命令,分别是"top -p 21475 -n 1 -b"和"sh /home/hadoop/project/flume-hdfs.sh start"。然后,对命令输出进行了一些处理,使用了一个名为"lineFreedList"的List来存储处理后的字符串。接着,对"lineFreedList"中的每个字符串进行了拆分处理,使用了一个名为"stringList"的List来存储拆分后的结果,最后将其打印出来。这段代码的作用是什么,需要根据上下文才能确定。
相关问题
帮我分析一下这段代码的作用try { long currentTimeMillis = System.currentTimeMillis(); ExecuteShellUtil instance = ExecuteShellUtil.getInstance(); instance.init("192.168.186.100", 22, "root","niit1234"); String ls = instance.execCmd("sh /home/hadoop/project/flume-hdfs.sh start"); List<String> lineFreedList = StrSplitter.splitByRegex(StrUtil.trimToEmpty(ls), "\n", -1, true, true); for (String s : lineFreedList) { List<String> stringList = StrSplitter.split(StrUtil.trimToEmpty(s), "=", -1, true, true); System.out.println(stringList); } System.out.println(ls); } catch (Exception e) { System.out.println("error info"); e.printStackTrace(); }
这段代码的作用是通过SSH连接到一个IP地址为"192.168.186.100",用户名为"root",密码为"niit1234"的Linux服务器,并执行一个名为"flume-hdfs.sh"的脚本文件,将其启动。然后,对脚本输出进行了一些处理,使用了一个名为"lineFreedList"的List来存储处理后的字符串。接着,对"lineFreedList"中的每个字符串进行了拆分处理,使用了一个名为"stringList"的List来存储拆分后的结果,最后将其打印出来。同时,将脚本输出也打印出来。如果连接或执行命令出现异常,则会输出"error info"并打印异常堆栈信息。
sn = code.substring(code.length() - 7); // 7位序列号 style = code.substring(code.length() - 10, code.length() - 7); // 3位款式 spec = code.substring(0, code.length() - 10); // 型号将数据放进集合里,但是不影响下面的代码
你可以使用ArrayList来创建一个集合,将数据放入集合中。代码如下:
```
List<String> dataList = new ArrayList<>();
String sn = code.substring(code.length() - 7); // 7位序列号
String style = code.substring(code.length() - 10, code.length() - 7); // 3位款式
String spec = code.substring(0, code.length() - 10); // 型号
// 将数据放进集合中
dataList.add(spec);
dataList.add(style);
dataList.add(sn);
```
注意:这里的dataList是一个List<String>类型的集合,如果你要使用其他类型的集合,可以根据需要进行修改。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
检查以下语法错误:<body> 返回 主页
编写人姓名: 胡莲 学号:20212310930228
<% request.setCharacterEncoding("UTF-8"); String sxh = request.getParameter("xh").trim(); String sname = request.getParameter("name").trim(); String sclassname = request.getParameter("classname").trim(); int sage = Integer.parseInt(request.getParameter("age")); String saddress = request.getParameter("address").trim(); String sphone = request.getParameter("phone").trim(); String scity = request.getParameter("city").trim(); String snotes = request.getParameter("notes").trim(); String sql = "update student set name='" + sname + "'" + ",classname='" + sclassname + "'" + ",age='" + sage + "'"+ "'" + ",address='" + saddress + "'"+ "'" + ",phone='" + sphone + "'"+ "'" + ",city='" + scity + "'"+ "'" + ",notes='" + snotes + "'"+ "where xh='" + sxh + "'"; try { java.sql.Connection conn = null; Class.forName("com.mysql.jdbc.Driver").newInstance(); //加载驱动程序 conn = java.sql.DriverManager .getConnection( "jdbc:mysql://localhost:3306/studentdb?useUnicode=true&characterEncoding=utf8", "root", "123456"); //URL指向数据库student PreparedStatement pstatement = conn.prepareStatement(sql); //建立SQL语句 pstatement.execute(); //执行SQL语句 out.print("学生(" + sxh + "," + sname + "," + sclassname + "," + sage + ")");//打印sql out.println("信息更新成功!"); pstatement.close(); conn.close(); } catch (SQLException e1) { System.out.print("sql语句失败!"); e1.printStackTrace(); } catch (Exception e2) { System.out.print("sql语句失败!"); e2.printStackTrace(); } %> </body>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)