📄 fso.java
字号:
package com.jspsmart.file;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */import java.io.*;// Referenced classes of package com.jspsmart.file:// FsoFilenameFilterpublic class Fso{ Fso() { } public static String getFilename(String s) { return (new File(s)).getName(); } public static boolean fileExists(String s) { return (new File(s)).isFile(); } public static void deleteFile(String s) throws IOException { File file = getAbsoluteParent(s); String s1 = getFilename(s); if(file.isDirectory()) { String as[] = file.list(new FsoFilenameFilter(s1)); if(as.length == 0) throw new FileNotFoundException(); for(int i = 0; i < as.length; i++) { File file1 = new File(file, as[i]); if(!file1.delete()) throw new IOException(); } } else { throw new FileNotFoundException(); } } public static boolean folderExists(String s) { File file = new File(s); return file.exists() && file.isDirectory(); } public static void deleteFolder(String s) throws IOException { File file = getAbsoluteParent(s); String s1 = getFilename(s); if(file.isDirectory()) { String as[] = file.list(new FsoFilenameFilter(s1)); if(as.length == 0) throw new FileNotFoundException(); for(int i = 0; i < as.length; i++) { File file1 = new File(file, as[i]); if(!file1.isDirectory() || !deleteFolder(file1)) throw new IOException(); } } else { throw new FileNotFoundException(); } } private static boolean deleteFolder(File file) { String as[] = file.list(); for(int i = 0; i < as.length; i++) { File file1 = new File(file, as[i]); if(file1.isDirectory()) { if(!deleteFolder(file1)) return false; } else if(!file1.delete()) return false; } return file.delete(); } public static void moveFile(String s, String s1) throws IOException { moveObject(s, s1); } public static void moveFolder(String s, String s1) throws IOException { moveObject(s, s1); } private static void moveObject(String s, String s1) throws IOException { if(!isPathExact(s) || s1.charAt(s1.length() - 1) == File.separatorChar) { if(!folderExists(s1)) throw new IOException(); File file = new File(s1); if(!isPathExact(s)) { File file2 = getAbsoluteParent(s); String s2 = getFilename(s); if(file2.isDirectory()) { String as[] = file2.list(new FsoFilenameFilter(s2)); if(as.length == 0) throw new FileNotFoundException(); for(int i = 0; i < as.length; i++) { File file6 = new File(file2, as[i]); File file7 = new File(file, as[i]); if(file7.exists() || !file6.renameTo(file7)) throw new IOException(); } } else { throw new FileNotFoundException(); } } else { File file3 = new File(s); File file5 = new File(file, getFilename(s)); if(file5.exists() || !file3.renameTo(file5)) throw new IOException(); } } else { File file1 = new File(s); File file4 = new File(s1); if(file4.exists() || !file1.renameTo(file4)) throw new IOException(); } } public static void copyFile(String s, String s1) throws IOException { if(!isPathExact(s) || s1.charAt(s1.length() - 1) == File.separatorChar) { if(!folderExists(s1)) throw new IOException(); File file = new File(s1); if(!isPathExact(s)) { File file2 = getAbsoluteParent(s); String s2 = getFilename(s); if(file2.isDirectory()) { String as[] = file2.list(new FsoFilenameFilter(s2)); if(as.length == 0) throw new FileNotFoundException(); for(int i = 0; i < as.length; i++) { File file6 = new File(file2, as[i]); File file7 = new File(file, as[i]); if(!file7.isDirectory()) copyFile(file6, file7); else throw new IOException(); } } else { throw new FileNotFoundException(); } } else { File file3 = new File(s); File file5 = new File(file, getFilename(s)); if(!file5.isDirectory()) copyFile(file3, file5); else throw new IOException(); } } else { File file1 = new File(s); File file4 = new File(s1); if(!file4.isDirectory()) copyFile(file1, file4); else throw new IOException(); } } private static void copyFile(File file, File file1) throws IOException { char c = '\u0400'; byte abyte0[] = new byte[c]; FileInputStream fileinputstream = new FileInputStream(file); BufferedInputStream bufferedinputstream = new BufferedInputStream(fileinputstream); FileOutputStream fileoutputstream = new FileOutputStream(file1); BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(fileoutputstream); int i; while((i = fileinputstream.read(abyte0)) != -1) fileoutputstream.write(abyte0, 0, i); bufferedoutputstream.close(); bufferedinputstream.close(); } public static void copyFolder(String s, String s1) throws IOException { if(!isPathExact(s) || s1.charAt(s1.length() - 1) == File.separatorChar) { if(!folderExists(s1)) throw new IOException(); File file = new File(s1); if(!isPathExact(s)) { File file2 = getAbsoluteParent(s); String s2 = getFilename(s); if(file2.isDirectory()) { String as[] = file2.list(new FsoFilenameFilter(s2)); if(as.length == 0) throw new FileNotFoundException(); for(int i = 0; i < as.length; i++) { File file6 = new File(file2, as[i]); File file7 = new File(file, as[i]); if(!file7.exists() || file7.isDirectory()) copyFolder(file6, file7); else throw new IOException(); } } else { throw new FileNotFoundException(); } } else { File file3 = new File(s); File file5 = new File(file, getFilename(s)); if(!file5.exists() || file5.isDirectory()) copyFolder(file3, file5); else throw new IOException(); } } else { File file1 = new File(s); File file4 = new File(s1); if(!file4.exists() || file4.isDirectory()) copyFolder(file1, file4); else throw new IOException(); } } private static void copyFolder(File file, File file1) throws IOException { if(!file1.exists() && !file1.mkdirs()) throw new IOException(); if(!file1.isDirectory()) throw new IOException(); String as[] = file.list(); for(int i = 0; i < as.length; i++) { File file2 = new File(file, as[i]); File file3 = new File(file1, as[i]); if(file2.isDirectory()) copyFolder(file2, file3); else copyFile(file2, file3); } } private static File getAbsoluteParent(String s) { File file = new File(s); File file1 = new File(file.getAbsolutePath()); File file2 = new File(file1.getParent()); return file2; } private static boolean isPathExact(String s) { return s.indexOf('*') == -1 && s.indexOf('?') == -1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -