首页 > 解决方案 > ftp 功能卡住后最终无法继续?

问题描述

我在 java 中有一个 FTP 功能-可以正常工作。我的问题是出现异常时 - 它不会完成,只是向我展示异常并卡住为什么?

public static void UploadFTP ()
    {
        String ftpUrl = "ftp://%s:%s@%s/%s";
        String host = "10.0.0.1";
        String user = "FTP";
        String pass = "FTP";
        String filePath="/home/pi/SendData.log";
        String uploadPath = "/car.txt";

        ftpUrl = String.format(ftpUrl,user,pass,host,uploadPath);
        System.out.println("Upload URL:  " + ftpUrl);
        try
        {
            URL url = new URL(ftpUrl);
            URLConnection conn = url.openConnection();
            OutputStream outputStream = conn.getOutputStream();
            FileInputStream inputStream = new FileInputStream
                (filePath);

            byte[] buffer = new byte [4096];
            int bytesRead = -1;
            while ((bytesRead = inputStream.read(buffer)) != -1)
            {
                outputStream.write(buffer,0,bytesRead);
            }

            inputStream.close();
            outputStream.close();
            System.out.println("File Upload Finish!");
        }

        catch (IOException ex)
        {
            ex.printStackTrace();
        }

        finally 
        {}

    }

我需要它来向我展示问题并返回到主代码,所以出了什么问题?

标签: javaexception-handlingftp

解决方案


推荐阅读