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

View File

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