2012-05-29 2 views
0

EDIT : children은 디렉토리의 배열입니다. 이 코드는 각 디렉토리를 입력하고 배열 에로드하기 위해이 배열을 반복합니다. 웹 모든 파일이 나열됩니다. 그런 다음 각 파일에 대해 readFile 함수는 파일을 읽어야합니다.Java 디렉토리의 파일을 읽는 데 이상한 오류가 발생했습니다.

내 코드입니다 : 그 디렉토리에 해당 파일가 표시되지 않기 때문에

org.htmlparser.util.ParserException: Error in opening a connection to 209800.webtrec 
209801.webtrec 
    ...  
422064.webtrec 
422071.webtrec 
422087.webtrec 
422089.webtrec 
422112.webtrec 
422125.webtrec 
422127.webtrec 
; 
java.io.IOException: File Name Too Long 
    at java.io.UnixFileSystem.canonicalize0(Native Method) 
at java.io.UnixFileSystem.canonicalize(UnixFileSystem.java:172) 
at java.io.File.getCanonicalPath(File.java:576) 
at org.htmlparser.http.ConnectionManager.openConnection(ConnectionManager.java:848) 
at org.htmlparser.Parser.setResource(Parser.java:398) 
at org.htmlparser.Parser.<init>(Parser.java:317) 
at org.htmlparser.Parser.<init>(Parser.java:331) 
at IndexGenerator.IndexGenerator.readFile(IndexGenerator.java:156) 
at IndexGenerator.IndexGenerator.main(IndexGenerator.java:101) 

그것은 이상한 :

for (File cat: children) { 
    File[] webs = cat.listFiles(); 
    System.out.println(" Indexing category: " + cat.getName()); 
    for (File f: webs) {      
     Web w = readFile(f);     
     // Do things with w 
    } 
} 

는이 오류를 받고 있어요.

감사합니다.

EDIT2 : 이것은 readFile 기능입니다. 파일의 내용을 문자열로로드하고 파싱합니다. 사실, 파일은 html 파일입니다.

private static Web readFile(File file) { 
    try {   
     FileInputStream fin = new FileInputStream(file); 
     FileChannel fch = fin.getChannel(); 

     // map the contents of the file into ByteBuffer 
     ByteBuffer byteBuff = fch.map(FileChannel.MapMode.READ_ONLY, 
       0, fch.size()); 

     // convert ByteBuffer to CharBuffer 
     // CharBuffer chBuff = Charset.defaultCharset().decode(byteBuff); 
     CharBuffer chBuff = Charset.forName("UTF-8").decode(byteBuff); 
     String f = chBuff.toString(); 

     // Close imputstream. By doing this you close the channel associated to it 
     fin.close();    

     Parser parser = new Parser(f);   
     Visitor visit = new Visitor(); 
     parser.visitAllNodesWith((NodeVisitor)visit);   
     return new Web(visit.getCat(), visit.getBody(), visit.getTitle()); 

    } catch (FileNotFoundException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (ParserException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    return null; 
} 
+3

'어린이'란 무엇입니까? 그거 어디서 났어 ? 'readFile'이란 무엇입니까? 소스 코드를 보여주십시오. 그것은 무엇을할까요? –

+3

예외가 발생한 파일의 이름을 인쇄 할 수 있습니까? – hage

+1

자바 버전이 무엇입니까? 이름이 너무 길어서 파일 이름이 너무 길지 않은 경우 자바를 업데이트하려고하면 버그 일 수 있습니다. – bpgergo

답변

0

좋아, 결국 해결책이 있습니다.

매우 바보 같은 오류입니다. 이전 작업에서 삭제 한 모든 빈 html 파일의 이름이 들어있는 파일이이 디렉토리에있었습니다. 그래서 파싱을 시도하고 파서가 HTML과 같은 URL을 해석하지 않을 것입니다 (태그와 많은 점이 없기 때문에 ...). 그 폴더에 수백만 개의 파일이 있기 때문에 파일을 쉽게 찾을 수 없습니다.

관련 문제