1.可以,不过,一般来说文件比较用行比较好一些
2。FileInputStream fi = new FileInputStream(file);
3.File file = new File(filepath); file.delete();
4.yes

解决方案 »

  1.   

    To new_zero(Swing):
    搂主是想判断不懂得文件中的内容是否相同
    所以哈希数恐怕不行 ^_^
      

  2.   

    1》RandomAccessFile file=new RandomAccessFile("文件名”);
    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数又怎么比较???  
      

  3.   

    请问Keepers文件比较用行怎么写?
      

  4.   

    private static String processOneLine(int lineNumber,
                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);
            }
        }
      

  5.   

    将文件按照行读入存放在两个ArrayList或者JTextPanel中
    然后按照顺序比较,
    具体怎么比较,那时算法的问题。例如递归或者回朔。