前段时间下了若干个图片,不知道那张没有下:)孰编了 查找文件 的一段程序!
程序原理:如果读到这个文件,表示找到;没有抛出异常。
程序如下:
import java.io.*; public class FindFiles { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int j = 0; try { String filePath = "D://mydoc09//My Pictures//Lin Si Yee//01"; for (int i = 1; i < 700; i++) { String preFileName = ""; if(i > 0 && i < 10){ preFileName = "000"; } if(i >= 10 && i < 100){ preFileName = "00"; } if(i >= 100 && i < 1000){ preFileName = "0"; } j = i; String fileName = preFileName + String.valueOf(i) + ".jpg"; System.out.println(preFileName + "-" + fileName); InputStream fileInputStream = new FileInputStream(filePath + "//" + fileName); fileInputStream.read(); } } catch (FileNotFoundException fnfex) { // TODO: handle exception System.err.println("This is file " + j + " not found!"); } catch (IOException ioex) { // TODO: handle exception } } }