comparefiles.java

来自「It basic java program to work with Two f」· Java 代码 · 共 60 行

JAVA
60
字号
import java.io.*;

// start of class CompareFiles
class CompareFiles
{
	public static void main(String args[])
	{
		File fr1= null; //declare file1
		File fr2= null; //declare file2
		
		try
		{

		fr1=new File("TeamProj.txt"); // open File1
		System.out.println(fr1+" exists");
		
		System.out.println("The File is "+ fr1.length()  +" long");
		if(fr1.canRead())
		System.out.println(" Ok to read");
		else
		System.out.println(" Not Ready to read");
		if(fr1.canWrite())
		System.out.println(" Ok to Write ");
		else
		System.out.println(" Not Ready to Write ");
	
		}
		catch(Exception e)
		{
			System.out.println("TeamProj.txt Not Found");
			
		}
		try
		{

		fr2=new File("TeamProj2.txt"); // open File2
		System.out.println("The File is "+ fr2.length()  +" long");
		System.out.println(fr2+" exists");
		if(fr2.canRead())
		System.out.println(" Ok to read");
		else
		System.out.println(" Not Ready to read");
		if(fr2.canWrite())
		System.out.println(" Ok to Write ");
		else
		System.out.println(" Not Ready to Write ");
		
		}
		catch(Exception e)
		{
			System.out.println("TeamProj2.txt Not Found");
		}
		
		if(fr2.lastModified() > fr1.lastModified()) // Compare Time
		System.out.println("The more Recent File is "+fr2);
		else
		System.out.println("The more Recent File is "+fr1);
		
	}
} // end class CompareFiles

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?