2012-09-24 1 views
0

다음 코드 조각은 잘 작동하며 많은 프로젝트에서 사용하고 있습니다. 그러나,이 하나의 프로젝트에 대해 예외가 발견되지 않는 파일이 있습니다.파일을 찾을 수 없습니다 예외, 코드 조각은 다른 프로젝트에서 완벽하게 작동합니다

FileInputStream myInput = new FileInputStream(
       System.getProperty("user.dir") + inputFile); 
     w = Workbook.getWorkbook(myInput); 
     // w = Workbook.getWorkbook(new File(inputFile)); 
     // w = Workbook.getWorkbook(new File(System.getProperty("user.dir"), 
     // inputFile)); 

이는 C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\application 폴더에 파일을 업로드 :

try { 
     FileInputStream is = new FileInputStream(file); 
     String original = file.getName(); 

     Logger.debug("Filename in upload pf %s ", original); 
     IOUtils.copy(is, new FileOutputStream(Play.getFile(original))); 

     PfParser p1 = new PfParser(); 
     p1.read(original, month, year); 

     Payroll.index(); 

    } catch (FileNotFoundException e) { 
     Logger.error(e, "Exception in uploadSheet: "); 
     e.printStackTrace(); 
    } catch (IOException e) { 
     Logger.error(e, "Exception in uploadSheet: "); 
     e.printStackTrace(); 
    } 

내가 주석 처리되어 몇 가지 조합을 시도 읽기 방법이다.

Jexcel을 사용하여 Excel 파일을 읽으려고합니다. 서버에 표시되는 오류 :

java.io.FileNotFoundException: foo.xls (The system cannot find the file specified) 
    at java.io.FileInputStream.open(Native Method) 
    at java.io.FileInputStream.<init>(Unknown Source) 
    at java.io.FileInputStream.<init>(Unknown Source) 

다른 줄 (주석 처리)을 시도하면 오류가 다양합니다.

java.io.FileNotFoundException: C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\foo.xls (The system cannot find the file specified) 

나는 절대 경로 및 상대 경로와 관련된 문제를 이해하고 있지만 해결책을 찾지 못하는 것 같습니다. Ubuntu 인 로컬 컴퓨터에서 코딩 및 테스트를하는 동안 오류가 발생하지 않습니다. Windows 서버에 배포 할 때만 이러한 문제가 발생합니다.

감사합니다.

+0

googled도 많이 있었고 vogella의 솔루션도 도움이되지 않았습니다. – theTuxRacer

답변

0

파일 위치 포함한 전체 스피 넷을 작성하는 경우 그것은 좋은 것입니다.

0

FileNotFound FileInputStream 생성자에서 제공하는 절대/상대 경로에 파일이 없을 때 예외가 발생합니다.

FileInputStream is = new FileInputStream(file); 

FileInputStream 생성자에서 올바른 위치를 제공하지 않는다고 생각합니다. 당신은 내가

업로드 이제 작동

IOUtils.copy(is, new FileOutputStream("./" + original));

IOUtils.copy(is, new FileOutputStream(Play.getFile(original)));

에서 라인 변경 등

+0

파일은'C : ₩ Program Files (x86) ₩ Apache Software Foundation ₩ Tomcat 6.0 ₩ webapps ₩ ROOT ₩ WEB-INF ₩ application'에 성공적으로 업로드되었습니다. – theTuxRacer

+0

경로없이 파일의 이름 만 나타납니다. – theTuxRacer

+0

** System.getProperty ("user.dir")의 변형/변경 사항은 ** Ubuntu ** 및 ** Windows ** 플랫폼에서 다를 수 있습니다. –