📄 paresfiles.java
字号:
package sun.com.tool;
import java.io.*;
import java.util.List;
import java.util.Vector;
import sun.com.exception.*;
import javax.swing.JOptionPane;
import sun.com.domain.Box;
import sun.com.domain.Ship;
public class ParesFiles {
private Vector<Box> box=new Vector<Box>();
private Vector<Ship> shp =new Vector<Ship>();
Ship ship=null;
//表头
public String[] title(){//����
// Vector<String> v=new Vector<String>();
// v.add("船名");
// v.add("航次");
// v.add("提单号");
// v.add("目的港");
// v.add("尺寸");
// v.add("箱形");
// v.add("数量");
// v.add("经营人");
// v.add("备注");
String title[]={"船名","航次","提单号","目的港","尺寸","箱形","数量","经营人","备注"};
return title;
}
//将文件进行解析
public Vector<Ship> pareFile(File file)throws Exception {
String shipMach = "[a-zA-Z]+:[0-9a-zA-Z]+:[a-zA-Z\\s0-9]+:[a-zA-Z]+";
String boxMach = "[0-9]+:[a-zA-Z]+:[0-9]+:[a-zA-Z]+";
BufferedReader bf;
bf = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
int option = -1;
String str;
while((str = bf.readLine())!= null){
String st = str.replace("#","");
if(st.matches(shipMach)) {
String[] s =st.split(":");
ship = new Ship(s[0],s[1],s[2],s[3]);
shp.add(ship);
option = option + 1;
}else if(st.matches(boxMach)){
String[] s =st.split(":");
//备注
String remark = "";
if (s[3].equals("SNL") || s[3].equals("HUB"))
remark = "SOC";
ship.getBox().add(new Box(s[0],s[1],s[2],s[3],remark));
}else{
throw new MyException("文件格式不正确!");
}
}
return shp;
}
// public Vector<Vector<String>> parseData(File file){//�������
// readData(file);
// Vector<Vector<String>> vector=new Vector<Vector<String>>();
// for(Ship p:shp){
// Vector<String> vrow=new Vector<String>();
// String Shipname=p.getShipname();
// String Voyage=p.getVoyage();
// String Blno=p.getBlno();
// String Destination=p.getDestination();
// vrow.add(Shipname);
// vrow.add(Voyage);
// vrow.add(Blno);
// vrow.add(Destination);
// vector.add(vrow);
// for(Box b:ship.getBox()){
// Vector<String> vrow1=(Vector<String>)vrow.clone();
// String Cntsize=b.getCntsize();
// String Cnttype=b.getCnttype();
// String Cntqnt=b.getCntqnt();
// String Cntoperator=b.getCntoperator();
// String Remark=b.getRemark();
// vrow1.add(Cntsize);
// vrow1.add(Cnttype);
// vrow1.add(Cntqnt);
// vrow1.add(Cntoperator);
// vrow1.add(Remark);
// vector.add(vrow1);
// System.out.println(vrow1.size());
// }
// }
// return vector;
// }
// public static void main(String[] args) {
// Tool tool=new Tool();
// File file=new File("D:\\06062314");
// Vector<Vector<String>> vect=tool.parseData(file);
// System.out.println("vect:"+vect.get(0));
// System.out.println("vect:"+vect.get(1));
// System.out.println("vect:"+vect.get(2));
// System.out.println("vect:"+vect.get(3));
// System.out.println("vect:"+vect.get(4));
//
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -