package my.scan; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; /** * Hello world! */ public class App { public static void main(String[] args) throws IOException { String file = args[0]; BufferedReader reader = new BufferedReader(new InputStreamReader( new FileInputStream(file), "utf-8")); String line = ""; List<String> listData1 = new ArrayList<>(); List<String> listData2 = new ArrayList<>(); List<String> listData3 = new ArrayList<>(); List<String> listData4 = new ArrayList<>(); int index = 0; while ((line = reader.readLine()) != null) { if (null == line || line.equals("")) { continue; } line = line.replaceAll(" ", ""); if (line.equals("")) { continue; } if (index % 4 == 0) { listData1.add(line); index++; continue; } if (index % 4 == 1) { listData2.add(line); index++; continue; } if (index % 4 == 2) { listData3.add(line); index++; continue; } if (index % 4 == 3) { listData4.add(line); index++; continue; } } System.out.println("listData1:" + listData1.size()); System.out.println("listData2:" + listData2.size()); System.out.println("listData3:" + listData3.size()); System.out.println("listData4:" + listData4.size()); ReadThread readThread1 = new ReadThread(); readThread1.setListData(listData1); readThread1.start(); ReadThread readThread2 = new ReadThread(); readThread2.setListData(listData2); readThread2.start(); ReadThread readThread3 = new ReadThread(); readThread3.setListData(listData3); readThread3.start(); ReadThread readThread4 = new ReadThread(); readThread4.setListData(listData4); readThread4.start(); } }
package my.scan; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.List; /** * @author : xu * @date : 2020/6/10 */ public class ReadThread extends Thread { public List<String> listData; @Override public void run() { int i = 0; for (String item : listData) { String[] content = item.split(","); if (content.length != 2 || content[0] == "") { System.out.println("formate error data." + item); continue; } String version = ""; if (content[1].trim() != "") { version = "?ver=" + content[1]; } String xmlParent = content[0].replace(".jpg", "") + "/"; readData(xmlParent + "scene.xml" + version); i++; if (i % 50 == 0) { System.out.println(Thread.currentThread().getName() + "--" + i); } } System.out.println("done,size" + listData.size()); } private void readData(String file) { if (!file.startsWith("http")) { return; } try { URL url = new URL(file); InputStream is = url.openStream(); BufferedInputStream bis = new BufferedInputStream(is); StringBuffer sb = new StringBuffer(); int len; byte[] temp = new byte[1024]; while ((len = bis.read(temp)) != -1) { sb.append(new String(temp, 0, len)); } if (!sb.toString().contains("scene")) { System.out.println("error file:" + file); } } catch (IOException e) { System.out.println("read file exception:" + file); } } public List<String> getListData() { return listData; } public void setListData(List<String> listData) { this.listData = listData; } }
在服务器后台执行指定文件的main方法,并且日志写入到指定文件
java -cp scene-1.0-SNAPSHOT.jar my.scan.App VR_Scene_CloudPath_ok.csv >>result.log 2>&1 &
执行后会返回程序的执行进程id。