在android中获取特定.sql文件的表大小
我正在复制一个.sql文件到另一个.sql文件。 我必须比较这些文件是否有任何更改我正在复制的新文件。
我的代码是:
public static void copyFile(File src, File dst) throws IOException { FileChannel inChannel = new FileInputStream(src).getChannel(); FileChannel outChannel = new FileOutputStream(dst).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } finally { if (inChannel != null) inChannel.close(); if (outChannel != null) outChannel.close(); } }
请帮助我比较这些文件。
我通过先计算文件的MD5来比较文件,然后比较MD5。 我使用的代码(在Kotlin中,但很容易翻译成Java):
object FileUtil { fun getMD5(path: String): String { val file = File(path) val inStream = FileInputStream(file) return getMD5(inStream) } fun getMD5(inputStream: InputStream): String { val messagedigest: MessageDigest try { messagedigest = MessageDigest.getInstance("MD5") val buffer = ByteArray(1024 * 1024 * 1) var len = inputStream.read(buffer) while (len > 0) { //该对象通过使用 update()方法处理数据messagedigest.update(buffer, 0, len) len = inputStream.read(buffer) } //对于给定数量的更新数据,digest 方法只能被调用一次。在调用 digest 之后,MessageDigest 对象被重新设置成其初始状态。 return StringUtils.convertHashToString(messagedigest.digest()) } catch (e: NoSuchAlgorithmException) { Log.e("Error", e.toString()) e.printStackTrace() } catch (e: OutOfMemoryError) { Log.e("OutOfMemoryError", e.toString()) e.printStackTrace() throw e } finally { inputStream.close() } return "" }
}
- Firebase:在Kotlin / Java中使用枚举字段的干净方式?
- 如何在kotlin编程语言中使用如下所述的循环?
- Firebase Perf不会运行测试应用程序:transformClassesWithFirebasePerformancePluginForDebugAndroidTest
- 从android应用程序内手动启动AutoBackup
- android -kotlin -java.lang.ClassCastException
- 无法从匿名类访问外部类
- 调用File.createNewFile()时,权限被拒绝 Android的
- Android Kotlin类实现的问题
- 格式@Query参数 – 改造2