📄 myfile.java
字号:
package md_accept;
import java.io.*;
import java.util.Enumeration;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
class myFile {
myFile() {
}
/**
* 将原路径下的所有文件copy到目标路径下,同名
* @param s:原路径
* @param s1:目标路径
*/
public void copy(String s, String s1) {
try {
File file = new File(s);
String as[] = file.list();
for (int i = 0; i < as.length; i++) {
File file1 = new File(s + "\\" + as[i]);
if (file1.isFile()) {
FileInputStream fileinputstream = new FileInputStream(file1);
FileOutputStream fileoutputstream = new FileOutputStream(new File(s1 +
"\\" + as[i]));
DataInputStream datainputstream = new DataInputStream(new
BufferedInputStream(fileinputstream));
do {
byte abyte0[] = new byte[1024];
int j = datainputstream.read(abyte0);
if (j == -1)
break;
fileoutputstream.write(abyte0, 0, j);
}
while (true);
datainputstream.close();
fileoutputstream.close();
}
}
}
catch (Exception e) {
System.out.println("拷贝目录" + s + "下后缀为" + s1 + "的文件出错:" + e.getMessage());
}
}
public void delete(String s) {
try {
File file = new File(s);
if (!file.isFile()) {
String as[] = (new File(s)).list();
for (int i = 0; i < as.length; i++) {
File file1 = new File(s + "\\" + as[i]);
if (file1.isFile()) {
File file2 = new File(s + "\\" + as[i]);
file2.delete();
}
}
}
else {
file.delete();
}
}
catch (Exception e) {
System.out.println("删除文件" + s + "出错" + e.getMessage());
}
}
/**
* 路径s下,是否存在文件s1
* @param s
* @param s1
* @return
*/
public boolean isExist(String s, String s1) {
boolean flag = false;
File file = new File(s);
String as[] = file.list();
for (int i = 0; i < as.length; i++) {
if (as[i].toUpperCase().compareTo(s1.toUpperCase()) != 0)
continue;
flag = true;
break;
}
return flag;
}
/**
* 目录path是否存在zip文件
* @param path
* @return
*/
public Vector getZipVector(String path) {
try {
File file = new File(path);
if (!file.exists())
return new Vector();
String as[] = file.list();
Vector vector = new Vector();
for (int i = 0; i < as.length; i++) {
File file1 = new File(path + "\\" + as[i]);
String s1 = as[i].substring(as[i].indexOf(".") + 1);
if (file1.isFile() && s1.compareToIgnoreCase("zip") == 0)
vector.add(as[i]);
}
return vector;
}
catch (Exception e) {
System.out.println("获得目录 " + path + " 的zip文件出错:" + e.getMessage());
return new Vector();
}
}
/**
* 目录path是否存在zip文件
* @param path
* @return
*/
public Vector getZipVector(String path,String flag) {
try {
File file = new File(path);
if (!file.exists())
return new Vector();
String as[] = file.list();
Vector vector = new Vector();
for (int i = 0; i < as.length; i++) {
File file1 = new File(path + "\\" + as[i]);
String s1 = as[i].substring(as[i].indexOf(".") + 1);
if(flag.equals("NSRXX")){//为纳税信息
if (file1.isFile() && as[i].indexOf("NSRXX") >= 0 &&
s1.compareToIgnoreCase("zip") == 0)
vector.add(as[i]);
}else{//反馈
if (file1.isFile() && as[i].indexOf("NSRXX") <0 &&
s1.compareToIgnoreCase("zip") == 0)
vector.add(as[i]);
}
}
return vector;
}
catch (Exception e) {
System.out.println("获得目录 " + path + " 的zip文件出错:" + e.getMessage());
return new Vector();
}
}
/**
* 获得某个目录path下的,所有的end文件
* @param path
* @return
*/
public Vector getEndVector(String path) {
Vector vector = null;
try {
File file = new File(path);
String as[] = file.list();
vector = new Vector();
for (int i = 0; i < as.length; i++) {
File file1 = new File(path + "\\" + as[i]);
String s1 = as[i].substring(as[i].indexOf(".") + 1);
if (file1.isFile() && s1.toUpperCase().compareTo("END") == 0)
vector.add(as[i]);
}
return vector;
}
catch (Exception e) {
System.out.println("获得目录 " + path + " 的end文件出错:" + e.getMessage());
return new Vector();
}
}
/**
* 获得配置文件属性
* @param s
* @param s1
* @return
*/
public String getConfigValue(String s, String s1) {
String s2 = null;
BufferedReader bufferedreader = null;
try {
File file = new File(s);
bufferedreader = new BufferedReader(new FileReader(file));
for (String s3 = bufferedreader.readLine(); s3 != null;
s3 = bufferedreader.readLine()) {
if (s3.indexOf(s1) == -1)
continue;
int i = s3.indexOf("=");
s2 = (s3.substring(i + 1)).trim();
break;
}
}
catch (Exception e) {
System.out.println("获得配置文件属性出错:" + e.getMessage());
}
finally {
try {
if (bufferedreader != null)
bufferedreader.close();
}
catch (Exception e) {}
}
return s2;
}
/**
* 删除目录下后缀为s1的文件
* @param path:目录
* @param s1:后缀
*/
public static void delete(String path, String s1) {
try {
String as[] = (new File(path)).list();
for (int i = 0; i < as.length; i++) {
File file = new File(path + "\\" + as[i]);
if (!file.isFile())
continue;
String s2 = as[i].substring(as[i].indexOf(".") + 1);
if (s2.compareToIgnoreCase(s1) != 0)
continue;
File file1 = new File(path + "\\" + as[i]);
file1.delete();
}
}
catch (Exception e) {
System.out.println("删除目录" + path + "下后缀为" +
s1 + "的文件出错:" + e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -