Skip to content

Commit eabb6f4

Browse files
committed
[+] 从Resource导出
1 parent 084fd47 commit eabb6f4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/cc/moecraft/utils/FileUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.io.InputStream;
56
import java.nio.charset.Charset;
67
import java.nio.file.Files;
78
import java.nio.file.Paths;
@@ -262,4 +263,16 @@ public static String readFileAsString(File file) throws IOException
262263

263264
return stringBuilder.toString();
264265
}
266+
267+
/**
268+
* 从resources导出
269+
* @param resourceClass 带resources的类
270+
* @throws IOException 复制错误
271+
*/
272+
public static void copyResource(Class resourceClass, String fileName, File toFile) throws IOException, NullPointerException
273+
{
274+
createDir(toFile.getParent());
275+
InputStream resourceAsStream = resourceClass.getClassLoader().getResourceAsStream(fileName);
276+
Files.copy(resourceAsStream, Paths.get(toFile.getAbsolutePath()));
277+
}
265278
}

0 commit comments

Comments
 (0)