日期:2014-05-20 浏览次数:20873 次
public class Test { /** * 获取路径下所有文件的名字 *@see * @param path * @return List<String> */ private static List getFiles(String path) { List files = new ArrayList(); File file = new File(path); getAllFiles(file, files); return files; } private static void getAllFiles(File file, List files) { if (file.isFile()) { files.add(file.getAbsolutePath()); } else { File[] fs = file.listFiles(); for (int i = 0; i < fs.length; i++) { File f = fs[i]; getAllFiles(f, files); } } } public static void main(String[] args) { List pngs = getFiles("D:\\workspace\\test"); List paths = getPath4JDBC(); pngs.removeAll(paths); for(int i = 0; i < pngs.size(); i++){ System.out.println((String)pngs.get(i)); } } public static List getPath4JDBC(){ List jdbcPaths = new ArrayList(); Connection conn = null; Statement st = null; ResultSet result = null; try { Class.forName("");//加载对应数据库的驱动 conn = DriverManager.getConnection("url", "user", "password");//根据对应数据库的url,user,password获取数据库连接 st = conn.createStatement(); result = st.executeQuery("select path from table");//写入你自己的sql while(result.next()){ jdbcPaths.add(result.getString("path"));//我这里暂且用path来获取 } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return jdbcPaths; } }