import java.util.*;
import java.io.*; public class Example {
public static void main(String[] args){
readFile("proxy.txt",0);
readFile("proxy.txt",1);
readFile("proxy.txt",4);
execSystemCmd("notepad"); // windows cmd
execSystemCmd("ls /home/whucs");
execSystemCmd("tail -n /home/whucs/vote.py");
execSystemCmd("wc -l php-fpm.log"); // count lines of a file. 500MB ~ 2s
} public static void readFile(String path, int beginLine) {
FileInputStream inputStream = null;
Scanner sc = null;
try {
inputStream = new FileInputStream(path);
sc = new Scanner(inputStream, "UTF-8");
int begin = 0;
if (beginLine == 0) beginLine = 1;
while (sc.hasNextLine()) {
begin ++;
if (begin >= beginLine) {
String line = sc.nextLine();
// TODO...
System.out.println(line);
} else {
sc.nextLine();
}
}
if (begin < beginLine) {
System.out.println("error! beginLine > file's total lines.");
}
inputStream.close();
sc.close();
} catch (IOException e) {
System.out.println("FileReader IOException!");
e.printStackTrace();
}
} public static void execSystemCmd(String cmd) {
String outPut = null;
System.out.println("cmd=" + cmd);
try
{
Process p = Runtime.getRuntime().exec(cmd);
InputStream is = p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuilder buf = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null) buf.append(line + "\n");
outPut = buf.toString();
System.out.printf("outPut = %s",outPut);
}
catch (IOException e)
{
e.printStackTrace();
}
} }

最新文章

  1. CS Coder学习asp.net5个月的最大感悟:从http的角度重新认识asp.net(二)——我理解的ajax(二)
  2. 常见的高可用MySQL解决方案
  3. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q121-Q124)
  4. centos下安装nagios
  5. Sqli-labs less 52
  6. Sublime Text2 多行编辑快捷键
  7. 用彩虹表破解MD5、LM Hash等复杂加密密码
  8. 【数据库摘要】4_Sql_Like
  9. Java 读写Properties配置文件
  10. AM335X的USB otg网卡(RNDIS /Ethernet Gadget)调试
  11. 搭建一个web服务下载HDFS的文件
  12. for循环语句/命名函数
  13. SQL Server进阶 遍历表的几种方法
  14. Tomcat/7.0.81 远程代码执行漏洞复现
  15. MySQL5.7版本及以上,改密码sql语句;grant创建用户已经密码
  16. Java EE 之 Hibernate异常总结【4】org.hibernate.exception.SQLGrammarException: could not execute statement
  17. arcgis api for flex 开发入门
  18. Java学习第1天:序言,基础及配置tomcat
  19. Autowired使用说明
  20. 初识PHP(一)

热门文章

  1. centos6.3部署配置LVS主从
  2. 关于Xcode9.0版本模拟器Reset重置操作变更
  3. 关于测试:JUnit4课程
  4. ASP.NET没有魔法——ASP.NET MVC IoC代码篇
  5. SQL 使用临时表和临时变量完成update表字段---实际案例
  6. AD域安装及必要设置
  7. git add 添加多个文件
  8. 我的第一个python web开发框架(24)——系统重构与ORM
  9. Eclipse链接数据库
  10. Pyqt5-Python应用开发——第一个小程序的实现