1. 程式人生 > >【檔案操作】Http的request上傳檔案獲取檔名稱

【檔案操作】Http的request上傳檔案獲取檔名稱

    public static String getFileName(InputStream is) throws IOException {
        StringBuffer sb = new StringBuffer();
        int count = 0;
        while (true) {
            int a = is.read();
            sb.append((char) a);
            if (a == '\r') {
                count++;
            }
            if (count == 4) {
                is.read();
                break;
            }
        }
        String title = sb.toString();
        System.out.println(title);
        String[] titles = title.split("\r\n");
        String fileName = titles[1].split(";")[2].split("=")[1].replace("\"", "");
        return fileName;
    }