簡體   English   中英

如何設置pdf文件路徑以從服務器下載文件

[英]how to set pdf file path to download the file from server

我想從服務器下載pdf,我從API響應中獲取的文件的路徑如下:E:\\ C1MS \\ REPORTS \\ 003315150418.pdf

但是,如何通過提供服務器的IP地址來下載此文件?

服務器的路徑是: http : //103.91.100.17 : 8080/creditOneFuelOneApp/

下載文件的代碼

public static void DownloadFile(String fileURL, File directory) {
    try {

        FileOutputStream f = new FileOutputStream(directory);
        URL u = new URL(fileURL);
        HttpURLConnection c = (HttpURLConnection) u.openConnection();
        c.setRequestMethod("GET");
        c.setDoOutput(true);
        c.connect();

        InputStream in = c.getInputStream();

        byte[] buffer = new byte[1024];
        int len1 = 0;
        while ((len1 = in.read(buffer)) > 0) {
            f.write(buffer, 0, len1);
        }
        f.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

編輯:

http://103.91.100.17:8080/creditOneFuelOneApp/statement

請求

    {
"account_number" : "000584",
"user_type" : "C"
}

響應

{
    "response_code": 0,
    "bill_due_date": "05-Jun-18",
    "last_bill_date": "01-Jun-18",
    "response_desc": "Success",
    "account_name": "Credit One",
    "last_bill_amount": "35083.00",
    "statement_list": [
        {
            "bill_amount": "35083.00",
            "file_location": "",
            "bill_date": "01-Jun-18",
            "due_date": "05-Jun-18"
        },
        {
            "bill_amount": "35083.00",
            "file_location": "E:\\C1MS\\REPORTS\\000584180501.pdf",
            "bill_date": "16-May-18",
            "due_date": "20-May-18"
        },
        {
            "bill_amount": "30083.00",
            "file_location": "E:\\C1MS\\REPORTS\\000584180401.pdf",
            "bill_date": "01-May-18",
            "due_date": "05-May-18"
        },
]

請幫忙。 謝謝。

FileOutputStream f = new FileOutputStream(new File(path + File.separator
                                          + fileName));

您的路徑在哪里:

new StringBuilder("E:").append(File.separator)
                       .append("C1MS")
                       .append(File.separator)
                       .append("REPORTS").toString();

和文件名: "003315150418.pdf"

看一下Oracle文檔oracle fileupload

你可以做這樣的事情。

String server_path = " http://103.91.100.17:8080/creditOneFuelOneApp/";
String server_location = "E:\C1MS\REPORTS\003315150418.pdf";

您還可以動態生成server_location字符串

現在像這樣調用您的downloadFile函數

DownloadFile(server_path,server_location)

public static void DownloadFile(String fileURL, File directory) {
    try {

        FileOutputStream f = new FileOutputStream(new File(directory));
        URL u = new URL(fileURL);
      //YOUR OTHER CODE
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM