- Long currentDate=System.currentTimeMillis();
- File outFile=new File("D:\\Upload\\"+currentDate+".txt");
- Ftp ftp = new Ftp("ip",port,"name","password");
- ftp.cd("/wuys");
- ftp.download("/wuys","eFile.txt",outFile);
- String node = "T_MONITOR_STATUS";//monitor status狀態監視器
- String beginDate= DateUtil.now();
- List<List<String>> nodeDatas = EfileReader.readEFile(outFile, node);
- for (int i = 0; i < nodeDatas.size(); i++) {
- List<String> lineDatas = nodeDatas.get(i);
- for (int j = 0; j < lineDatas.size(); j++) {
- System.out.print(lineDatas.get(j)+"\t");
- }
- System.out.println();
- }
- String endDate=DateUtil.now();
- System.out.println("開始時間:"+beginDate+" 結束時間:"+endDate);
- ftp.close();
- ----------------readEFile方法如下
- public static List<List<String>> readEFile(File eFilePath, String node){
- try {
- int startIndex = 0;
- int thisIndex = 0;
- int endIndex = 0;
- boolean flag = false;
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(eFilePath),"UTF-8"));
- String line = reader.readLine();
- List<List<String>> listDatas = new ArrayList<List<String>>();
- while ((line = reader.readLine()) != null && flag == false) {
- thisIndex++;
- if(line.startsWith("<"+node)){
- startIndex = thisIndex;
- }
- else if(line.startsWith("</"+node)){
- endIndex = thisIndex;
- flag = true;
- }
- else if(startIndex != 0){
- String[] split = line.split("\\s+");
- List<String> lineDatas = new ArrayList<String>(Arrays.asList(split));
- lineDatas.remove(0);//刪除第一個元素,比如:@、#
- listDatas.add(lineDatas);
- }
- }
- //System.err.println(node+"節點標籤在第"+startIndex+"-"+endIndex);
- reader.close();
- return listDatas;
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
讀取FTP上的E文件並進行解析
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.