1.可以,不过,一般来说文件比较用行比较好一些
2。FileInputStream fi = new FileInputStream(file);
3.File file = new File(filepath); file.delete();
4.yes
2。FileInputStream fi = new FileInputStream(file);
3.File file = new File(filepath); file.delete();
4.yes
解决方案 »
- 要从OOP编写的程序总结一个流程图应该怎样画?
- GridLayout布局,JPanel上的添加的JScroll没有用。
- 请问JAVE程序语言的平台无关性
- 帮忙编一个简单的程序,今天下午要用,编好就结贴,谢谢!! 急急急!!!
- 怎么固定JInternalFrame不被拖动
- 在linux下能否用java来读写excel文件呀? 谢谢。
- 请教 import mypackage.* 和 import mypackage.TheClass的区别?
- 总在这时才知道俺的差:莫名其妙的错误???VS俺太菜????
- 何谓JIT技术?
- 新人求告诉为什么在html编写代码页面引用不成JQuery。
- 如何在应用程序里调用IE访问web页面?
- 大哥们救命呀!!!
搂主是想判断不懂得文件中的内容是否相同
所以哈希数恐怕不行 ^_^
file.length()既然返回的是这个文件字节数的总和
那么请看这段代码
long length;
RandomAccessFile file=new RandomAccessFile("文件名”);'
length=file.length();
byte buffer[]=new byte[length];
int bytes=fileIn.read(buffer,0,length);
最后这行应该能行吧~(就是那个length的用的对不对???)???
2》可我按上述方法比较两个不同文件的时候~为什么他总是返回显示两个文件相等???
是否每个不同的文件的以字节表示的内容都不同??
3》上面说的文件按行比较怎么比较???
按hash数又怎么比较???
BufferedReader expectedData,
BufferedReader actualData)
throws IOException
{ String problem = null;
String expectedLine = expectedData.readLine();
if (!actualData.ready())
{
problem = "at line " + lineNumber + ", expected:\n" +
expectedLine + "\n" +
"but actual file was not ready for reading at this line.";
}
else
{
String actualLine = actualData.readLine();
if (!expectedLine.equals(actualLine))
{
// Uh oh, they did not match.
problem = "at line " + lineNumber + " there was a mismatch. Expected:\n";
int maxLen = expectedLine.length();
if (expectedLine.length() > actualLine.length())
{
maxLen = actualLine.length();
}
int startOffset = 0;
for (int i = 0; i < maxLen; i++)
{
if (expectedLine.charAt(i) != actualLine.charAt(i))
{
startOffset = i;
break;
}
}
problem += expectedLine.substring(startOffset) + "\n" +
"actual was:\n" +
actualLine.substring(startOffset) + "\n";
}
}
return problem;
} public static void assertEquals(BufferedReader expected,
BufferedReader actual) throws Exception
{
Assert.assertNotNull(expected);
Assert.assertNotNull(actual); String problem = null;
try
{
int lineCounter = 0;
while (expected.ready() && problem == null)
{
problem = processOneLine(lineCounter, expected, actual);
lineCounter++;
}
}
finally
{
expected.close();
actual.close();
} if (problem != null)
{
Assert.fail(problem);
}
}
然后按照顺序比较,
具体怎么比较,那时算法的问题。例如递归或者回朔。