
org.bhu.io.IOHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Baturu Show documentation
Show all versions of Baturu Show documentation
This is a IO library for NLP
package org.bhu.io;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class IOHelper {
public static String inputStream2String(InputStream is) {
BufferedReader in = new BufferedReader(new InputStreamReader(is));
StringBuffer buffer = new StringBuffer();
String line = "";
try {
while ((line = in.readLine()) != null) {
buffer.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return buffer.toString();
}
/**
* 删除空目录
*
* @param dir 将要删除的目录路径
*/
public static void doDeleteEmptyDir(String dir) {
boolean success = (new File(dir)).delete();
if (success) {
System.out.println("Successfully deleted empty directory: " + dir);
} else {
System.out.println("Failed to delete empty directory: " + dir);
}
}
//删除文件和目录
public static void clearFiles(String path){
File file = new File(path);
if(file.exists()){
deleteFile(file, file);
}
}
public static void deleteFile(File file, File remain){
if(file.isDirectory()){
File[] files = file.listFiles();
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy