|
Java 实例 - 文件路径比较
以下实例演示了使用 File 类的 filename.compareTo (another filename) 方法来比较两个文件路径是否在同一个目录下: Main.java 文件 import java . io . File ;
public class Main {
public static void main ( String [ ] args ) {
File file1 = new File ( " C:/File/demo1.txt " ) ;
File file2 = new File ( " C:/java/demo1.txt " ) ;
if ( file1 . compareTo ( file2 ) == 0 ) {
System . out . println ( " 文件路径一致! " ) ;
} else {
System . out . println ( " 文件路径不一致! " ) ;
}
}
} |
以上代码运行输出结果为:
文件路径不一致!
程序猿的技术大观园:www.javathinker.net
[这个贴子最后由 flybird 在 2020-01-27 16:07:23 重新编辑]
|
网站系统异常
系统异常信息 |
Request URL:
http://www.javathinker.net/WEB-INF/lybbs/jsp/topic.jsp?postID=1510&pages=31
java.lang.NullPointerException
如果你不知道错误发生的原因,请把上面完整的信息提交给本站管理人员。
|
|