本文實(shí)例講述了Java編程實(shí)現(xiàn)判斷網(wǎng)上鄰居文件是否存在的方法。分享給大家供大家參考,具體如下:
由于java不支持通過//192.168.19.168/fz/OK/張立辰-國(guó)畫/jpg/ZLC-魚1-X.jpg這種路徑
需要將路徑映射為本地盤,則可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package test; import java.io.File; public class FileCheck { /** * @param args */ public static void main(String[] args) { String filename= "d://test.xml" ; filename= "o://test.xml" ; filename= "o://t" ; filename= "o://學(xué)習(xí)//學(xué)習(xí).txt" ; File f= new File(filename); if (f.exists()) { if (f.isFile()) { System.out.println( "is file exist " ); } else { System.out.println( "is folder exist " ); } } else { System.out.println( "no" ); } System.out.println(checkFileExist(filename)); } public static boolean checkFileExist(String filename) { //String filename="d://test.xml"; //filename="o://test.xml"; File f= new File(filename); if (f.exists()) { System.out.println( "filename:" +filename+ " exist" ); return true ; } else { System.out.println( "filename:" +filename+ " not exist" ); return false ; } } } |
希望本文所述對(duì)大家Java程序設(shè)計(jì)有所幫助。