我正在尝试上传到我的服务器一个简单的文本文件~120b
我可以看到程序进入我的服务器并创建文件 - 但不会复制
中的数据它只是创建一个空的txt文件 (代码也是清除旧数据并将新数据写入文件 - 但我不认为这是问题) 我错过了什么\做错了?
long upload = TimeBetweenDates(SendTime,Time);
if (upload > 10)
{
String udp = String.join("!",
date,
time,
status,
final,
);
// SendUDP(udp);
output.append ( udp );
UploadFTP();
output.close();
//this part for clearing the data in the file
PrintWriter writer = new PrintWriter(PathOfFile);
writer.print("");
writer.close();
SendTime = Calendar.getInstance();
}
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();
}
}