import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileUtils {
public static void saveFile(String fileName, String content) {
String filePath = System.getProperty("user.dir");
File file = new File(new StringBuilder().append(filePath).append("/file/").append(fileName).toString());;
if (file.exists()) {
file.delete();
saveFile(fileName, content);
} else {
String absolutePath = file.getAbsolutePath();
int lastIndex = absolutePath.lastIndexOf(File.separator);
File dir = new File(absolutePath.substring(0, lastIndex));
if (!(dir.isDirectory())) {
dir.mkdirs();
}
try {
file.createNewFile();
writFile(file, content);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void writFile(File file, String content) throws Exception {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
buf = content.getBytes();
fos.write(buf);
} finally {
if (fos != null)
fos.close();
}
}
}