java - 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
{}
}
我需要它来向我展示问题并返回到主代码,所以出了什么问题?
解决方案
推荐阅读
- react-native - 将代码提取到外部函数 React native
- node.js - 如何使用 NodeJS(RobotJS 除外)导致键盘操作?
- wpf - WPF Vertical WrapPanel 拉伸以填充空间
- arrays - 我使用的是 pacman 的简单版本,但我不知道如何找到从 ghost 到 pacman 的路径:你能帮帮家伙吗
- database - 如何从一个表中调用 SQL 顺序函数作为对另一个表的引用?
- flutter - 尝试将列表用作带有 bloc 库的状态
- python-3.x - 无法从谷歌下载图片`
- docker - 如何从 GKE 节点拉取/推入 GCR
- angular - Angular 11 并保留一个基本网址
- azure - 如何使用 Jenkins 管道从 docker-compose 创建 docker 映像?