2012-12-08 4 views
0

파일의 전체 텍스트를 읽고 특정 구분 기호에 따라 분할하고 싶습니다. Java로 어떻게 할 수 있습니까?Java에서 txt 파일의 내용을 읽고 분할하는 방법은 무엇입니까?

+1

읽기, 스플 릿, 쓰기 ... 단순 – Frank

+0

string.split()? – ceklock

+0

파일을 분할하려면 하나의 조건이 있어야합니다. 크기 [바이트]/delimeter를 기준으로 분할하려고합니다. 질문을 완료하십시오 – Pavan

답변

0

내용을 읽으십시오. 분할 할 각 줄/단어 또는 구를 확인하려는 구분 기호를 선택하십시오. 스위치 케이스를 설치하십시오. 스위치 케이스를 기반으로 찾은 컨텐츠는 무엇이든 수행 할 수 있습니다. 다른 경우의 다른 텍스트 파일을 쓸 수 있다고 해봅시다.

2
try{ 
    // Open the file 
    FileInputStream fstream = new FileInputStream("textfile.txt"); 
    // Get the object of DataInputStream 
    DataInputStream in = new DataInputStream(fstream); 
    BufferedReader br = new BufferedReader(new InputStreamReader(in)); 
    String strLine; 
    //Read File Line By Line 
    while ((strLine = br.readLine()) != null) { 
    // split the line on your splitter(s) 
    String[] splitted = strLine.split("-"); // here - is used as the delimiter 
    } 
    //Close the input stream 
    in.close(); 
    }catch (Exception e){//Catch exception if any 
    System.err.println("Error: " + e.getMessage()); 
    } 
+0

답장을 보내 주셔서 감사합니다. – AyaZoghby

+0

하지만 텍스트를 한 줄씩 읽어야하는 이유는 무엇입니까? 그 결과 라인의 끝 부분 인 여분의 위치에 침을 뱉어 버리기 때문에 결과에 오류가 발생할 수 있습니다 !! – AyaZoghby

관련 문제