可能重复:
比较2个java语言文本文件的内容
我正在尝试在 android 应用程序中比较两个 .txt 文件的字符串。你能告诉我如何进行吗?我想在其中插入代码
try {
URL url = new URL("httpurl");
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
FileOutputStream fos = new FileOutputStream("/mnt/sdcard/random.txt");
fos.write(baf.toByteArray());
fos.close();
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}