請教各位,如何讀取war包中的檔案

hahafo發表於2004-07-20
專案要求我下載war包中的檔案,我在本地用weblogic釋出module的時候可以實現從工程目錄中下載,但是打成war包後,用weblogic釋出的時候卻拋FileNotFound Exception,請各位看看幫忙解決,不勝感激。

public static String getFileName(
        String pathKey,
        String fileNmKey,
        HttpServlet servlet)
        {
        String configBundleNm = "存放檔案路徑及檔名的資原始檔名";
        String fullName = null;

        try {
            PropertyResourceBundle configBundle =
                (PropertyResourceBundle) PropertyResourceBundle.getBundle(
                    configBundleNm,
                    Locale.getDefault());

            String fileName = (String) configBundle.getString(fileNmKey).trim();
            String path = (String) configBundle.getString(pathKey).trim();
            String fullPath = servlet.getServletContext().getRealPath(path);
            String fileSeparator =
                System.getProperties().getProperty("file.separator");
            fullName =
                new StringBuffer()
                    .append(fullPath)
                    .append(fileSeparator)
                    .append(fileName)
                    .toString();
        } catch (MissingResourceException missE) {

        }

        File file = new File(fullName);
        if (!file.isFile()) {

        }

        return fullName;

    }

相關文章