2013-12-13 2 views
0

나는 JAR에 넣을 때까지 작업 한 다음 코드File 객체를 사용하여 리소스에 액세스 할 수 있습니까?

 try { 
      URL url = getClass().getResource(""); 
      log.debug("url = '{}'", url.toString()); 

      URI uri = url.toURI(); 
      log.debug("uri = '{}'", uri.toString()); 

      File dir = new File(uri); 

      files = dir.listFiles(new FilenameFilter() { 
       @Override 
       public boolean accept(File dir, String name) { 
        return name.toLowerCase().endsWith(".ttf"); 
       } 
      }); 

      indice = new Integer[files.length]; 
      delegate = new Descr[files.length]; 
      fileNames = new String[files.length]; 
      fontNames = new String[files.length]; 

      for(int i=0; i<files.length; ++i) { 
       delegate[i] = new Descr(Font.createFont(Font.TRUETYPE_FONT, files[i]).deriveFont(FontSize)); 
       fileNames[i] = files[i].getName(); 
       fontNames[i] = delegate[i].getFont().getFontName(); 
      } 



     } catch (URISyntaxException e) { 
      throw new AssertionError(e); 
     } catch (FontFormatException e) { 
      throw new RuntimeException(e); 
     } catch (IOException e) { 
      throw new RuntimeException(e); 
     } 

와 폰트 자원에 접근했다. 그것이 원인이 JAR 및 오류

IllegalargumentException: URI is not hierarchicalhierarchical 

에서 그럼, 어떻게 JAR 내부 자원을 열거하려면? File을 사용할 수 있습니까?

답변

0

File 객체로 리소스에 액세스 할 수 있습니까?

아니요, 더 이상 파일이 아닙니다.

JAR 내부의 리소스를 열거하는 방법은 무엇입니까? 파일을 사용할 수 있습니까?

누군가가 질문 할 때마다 지구에서 왜 그렇게해야하는지 궁금합니다. Jar 파일을 빌드 할 때 Jar 파일의 '알려진 위치'에 자원 목록을 작성하십시오. 런타임에 목록을 가져 와서 파싱하고 거기서 가십시오.

+0

물론 생성이 불가능한 경우 목록을 하드 코딩합니다. 필자의 경우이 글꼴은 글꼴이며 새 글꼴을 쉽게 추가 할 수 있습니다. –

+0

의견이 있으십니까? 그렇다면 그것은 내게 없어졌습니다. –

관련 문제