에 입력 정보를 당겨야하는 것은 edifile입니다 * 0 * P * : ~ GS * FA * HMES * MGLYNNCO * 20120321 * 1220 * 15691 * X * 004010 ~ ST * 997 * 000015730 ~ AK1 * SM * 18292 ~ AK2 * 204 * 182920001 ~ AK5 * A ~ AK9 * A * 1 * 1 * 1 ~ SE * 6 * 000015730 ~ GE * 1 * 15,691 ~ IEA * 내가 통해 분석 할 필요가 EDI 파일이 내가 문자열을 구문 분석하고 데이터베이스 여기
JAVA
1 * 000015676 ~. 내가 파일을 얻을 수 있고 그것을 문자열로 변환하고 그것을 분쇄하기 위해 tokenizer를 사용했는데, 내가 확신 할 수없는 문제는 각 세그먼트에 다른 구분 기호가 있다는 것이다. 세그먼트 구분 기호에서 어떻게 구분할 수 있는가?
public class EdiParserP {
public static void main(String[] args) {
//retrieves the file to be read
File file = new File(args[0]);
int ch;
StringBuffer strContent = new StringBuffer("");
FileReader fileInSt = null;
try{
fileInSt = new FileReader(file);
while ((ch = fileInSt.read()) != -1)strContent.append((char)ch);
fileInSt.close();
}
catch (FileNotFoundException e)
{
System.out.println("file" + file.getAbsolutePath()+ "could not be found");
}
catch (IOException ioe) {
System.out.println("problem reading the file" + ioe);
}
System.out.println("File contents:" + "\n" + strContent + "\n");//used to check to see if file is there
System.out.print("Length of file" +" " + strContent.length()+ "\n"+ "\n");//used to count the length of the file
String buffFile = strContent.toString();//used to convert bufferstring to string
//breaks apart the file with the given delimiter
StringTokenizer st = new StringTokenizer(buffFile , "*");
while(st.hasMoreTokens())
{
String s =st.nextToken();
System.out.println(s);
}
}
}
나는 내 두 번째 질문은 데이터베이스에 넣어 정보를 검색하는 방법은 다음 생각, 나는 데이터베이스에 연결하는 방법을 알고, 그리고 삽입하는 방법, 내가 생각, 난 그냥 당겨하는 방법 확실하지 오전 이 문자열에서 나온 데이터? 도움을 주셔서 감사합니다
아마 http://edireader.sourceforge.net/와 같은 기성품 EDI 파서를 사용할 수 있습니까? 어쨌든 문자열을 올바르게 구문 분석하려면 문자열의 사양을 사용해야합니다. –
왜 추가 구분 기호가 포함 된 토큰에 string.split을 수행 할 수 없습니까? –
ediparser에 대해 알고 있지만 사용하기 전에 어떻게 작동하는지 이해하려고합니다. – warbunch