This commit is contained in:
Looly
2021-09-10 09:32:00 +08:00
parent 7a25b73376
commit a0f407865e
2 changed files with 55 additions and 52 deletions

View File

@@ -22,14 +22,15 @@ import java.util.Map.Entry;
/**
* 文件写入器
* @author Looly
*
* @author Looly
*/
public class FileWriter extends FileWrapper {
private static final long serialVersionUID = 1L;
/**
* 创建 FileWriter
*
* @param file 文件
* @param charset 编码,使用 {@link CharsetUtil}
* @return FileWriter
@@ -40,6 +41,7 @@ public class FileWriter extends FileWrapper{
/**
* 创建 FileWriter, 编码:{@link FileWrapper#DEFAULT_CHARSET}
*
* @param file 文件
* @return FileWriter
*/
@@ -48,8 +50,10 @@ public class FileWriter extends FileWrapper{
}
// ------------------------------------------------------- Constructor start
/**
* 构造
*
* @param file 文件
* @param charset 编码,使用 {@link CharsetUtil}
*/
@@ -60,6 +64,7 @@ public class FileWriter extends FileWrapper{
/**
* 构造
*
* @param file 文件
* @param charset 编码,使用 {@link CharsetUtil#charset(String)}
*/
@@ -69,6 +74,7 @@ public class FileWriter extends FileWrapper{
/**
* 构造
*
* @param filePath 文件路径相对路径会被转换为相对于ClassPath的路径
* @param charset 编码,使用 {@link CharsetUtil}
*/
@@ -78,6 +84,7 @@ public class FileWriter extends FileWrapper{
/**
* 构造
*
* @param filePath 文件路径相对路径会被转换为相对于ClassPath的路径
* @param charset 编码,使用 {@link CharsetUtil#charset(String)}
*/
@@ -88,6 +95,7 @@ public class FileWriter extends FileWrapper{
/**
* 构造<br>
* 编码使用 {@link FileWrapper#DEFAULT_CHARSET}
*
* @param file 文件
*/
public FileWriter(File file) {
@@ -97,6 +105,7 @@ public class FileWriter extends FileWrapper{
/**
* 构造<br>
* 编码使用 {@link FileWrapper#DEFAULT_CHARSET}
*
* @param filePath 文件路径相对路径会被转换为相对于ClassPath的路径
*/
public FileWriter(String filePath) {
@@ -287,15 +296,11 @@ public class FileWriter extends FileWrapper{
* @throws IORuntimeException IO异常
*/
public File write(byte[] data, int off, int len, boolean isAppend) throws IORuntimeException {
FileOutputStream out = null;
try {
out = new FileOutputStream(FileUtil.touch(file), isAppend);
try (FileOutputStream out = new FileOutputStream(FileUtil.touch(file), isAppend)) {
out.write(data, off, len);
out.flush();
} catch (IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(out);
}
return file;
}
@@ -391,6 +396,7 @@ public class FileWriter extends FileWrapper{
/**
* 打印新行
*
* @param writer Writer
* @param lineSeparator 换行符枚举
* @since 4.0.5

View File

@@ -231,9 +231,6 @@ public class UploadFile {
} finally {
IoUtil.close(out);
}
// if (getFileName().length() == 0 && size == 0) {
// size = -1;
// }
return true;
}