大文件上传ftp,不知道有没有上传完成,如果没有上传完成另一个程序去下载这个文件,导致下载不完整。

判断一个文件是否上传完成的方法:

/**
	 * 间隔一段时间去计算文件的长度来判断文件是否写入完成
	 * @param fileName
	 * @return
	 * @throws Exception
	 */
	private static boolean fileCreateSuccess(String fileName){
		try {
			File file;
			file=new File(fileName);
			long len1 = 0,len2=0;
			len2=file.length();
			do {
				len1=len2;
				//线程休息1s
				Thread.sleep(1000);
				file=new File(fileName);
				len2=file.length();
			} while (len1<len2);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("文件创建失败!!");
			return false;
		}
		

 

相关文章:

  • 2021-09-15
  • 2021-10-14
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案