springboot 常用工具(IOUtils、FileUtils)

****************************

相关类

IOUtils:输入输出流操作

public class IOUtils {****************
使用缓冲读取数据public static InputStream toBufferedInputStream(InputStream input) throws IOException {public static InputStream toBufferedInputStream(InputStream input, int size) throws IOException {public static BufferedInputStream buffer(InputStream inputStream) {public static BufferedInputStream buffer(InputStream inputStream, int size) {public static BufferedReader toBufferedReader(Reader reader) {public static BufferedReader toBufferedReader(Reader reader, int size) {public static BufferedReader buffer(Reader reader) {public static BufferedReader buffer(Reader reader, int size) {****************
使用缓冲输出数据public static BufferedWriter buffer(Writer writer) {public static BufferedWriter buffer(Writer writer, int size) {public static BufferedOutputStream buffer(OutputStream outputStream) {public static BufferedOutputStream buffer(OutputStream outputStream, int size) {***************
将数据读入内存public static byte[] toByteArray(InputStream input) throws IOException {public static byte[] toByteArray(InputStream input, long size) throws IOException {public static byte[] toByteArray(InputStream input, int size) throws IOException {public static byte[] toByteArray(Reader input, Charset encoding) throws IOException {public static byte[] toByteArray(Reader input, String encoding) throws IOException {public static byte[] toByteArray(URI uri) throws IOException {public static byte[] toByteArray(URL url) throws IOException {public static byte[] toByteArray(URLConnection urlConn) throws IOException {****************
将数据转换为字符数组public static char[] toCharArray(InputStream is, Charset encoding) throws IOException {public static char[] toCharArray(InputStream is, String encoding) throws IOException {public static char[] toCharArray(Reader input) throws IOException {*******************
将数据转换为字符串public static String toString(InputStream input, Charset encoding) throws IOException {public static String toString(InputStream input, String encoding) throws IOException {public static String toString(Reader input) throws IOException {public static String toString(URI uri, Charset encoding) throws IOException {public static String toString(URI uri, String encoding) throws IOException {public static String toString(URL url, Charset encoding) throws IOException {public static String toString(URL url, String encoding) throws IOException {public static String toString(byte[] input, String encoding) throws IOException {****************
resource转换为string、byte[]、URLpublic static String resourceToString(String name, Charset encoding) throws IOException {public static String resourceToString(String name, Charset encoding, ClassLoader classLoader) throws IOException {public static byte[] resourceToByteArray(String name) throws IOException {public static byte[] resourceToByteArray(String name, ClassLoader classLoader) throws IOException {public static URL resourceToURL(String name) throws IOException {public static URL resourceToURL(String name, ClassLoader classLoader) throws IOException {*******************
读取行数据转换为字符串public static List<String> readLines(InputStream input, Charset encoding) throws IOException {public static List<String> readLines(InputStream input, String encoding) throws IOException {public static List<String> readLines(Reader input) throws IOException {public static LineIterator lineIterator(Reader reader) {public static LineIterator lineIterator(InputStream input, Charset encoding) throws IOException {public static LineIterator lineIterator(InputStream input, String encoding) throws IOException {*******************
转换为输入流public static InputStream toInputStream(CharSequence input, Charset encoding) {public static InputStream toInputStream(CharSequence input, String encoding) throws IOException {public static InputStream toInputStream(String input, Charset encoding) {public static InputStream toInputStream(String input, String encoding) throws IOException {******************
将数据写入到输出流public static void write(byte[] data, OutputStream output) throws IOException {public static void writeChunked(byte[] data, OutputStream output) throws IOException {public static void write(byte[] data, Writer output, Charset encoding) throws IOException {public static void write(byte[] data, Writer output, String encoding) throws IOException {public static void write(char[] data, Writer output) throws IOException {public static void writeChunked(char[] data, Writer output) throws IOException {public static void write(char[] data, OutputStream output, Charset encoding) throws IOException {public static void write(char[] data, OutputStream output, String encoding) throws IOException {public static void write(CharSequence data, Writer output) throws IOException {public static void write(CharSequence data, OutputStream output, Charset encoding) throws IOException {public static void write(CharSequence data, OutputStream output, String encoding) throws IOException {public static void write(String data, Writer output) throws IOException {public static void write(String data, OutputStream output, Charset encoding) throws IOException {public static void write(String data, OutputStream output, String encoding) throws IOException {public static void writeLines(Collection<?> lines, String lineEnding, OutputStream output, Charset encoding) throws IOException {public static void writeLines(Collection<?> lines, String lineEnding, OutputStream output, String encoding) throws IOException {public static void writeLines(Collection<?> lines, String lineEnding, Writer writer) throws IOException {***********************
输入流复制到输出流public static int copy(InputStream input, OutputStream output) throws IOException {public static long copy(InputStream input, OutputStream output, int bufferSize) throws IOException {public static long copyLarge(InputStream input, OutputStream output) throws IOException {public static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException {public static long copyLarge(InputStream input, OutputStream output, long inputOffset, long length) throws IOException {public static long copyLarge(InputStream input, OutputStream output, long inputOffset, long length, byte[] buffer) throws IOException {public static void copy(InputStream input, Writer output, Charset inputEncoding) throws IOException {public static void copy(InputStream input, Writer output, String inputEncoding) throws IOException {public static int copy(Reader input, Writer output) throws IOException {public static long copyLarge(Reader input, Writer output) throws IOException {public static long copyLarge(Reader input, Writer output, char[] buffer) throws IOException {public static long copyLarge(Reader input, Writer output, long inputOffset, long length) throws IOException {public static long copyLarge(Reader input, Writer output, long inputOffset, long length, char[] buffer) throws IOException {public static void copy(Reader input, OutputStream output, Charset outputEncoding) throws IOException {public static void copy(Reader input, OutputStream output, String outputEncoding) throws IOException {******************
比较流是否相等public static boolean contentEquals(InputStream input1, InputStream input2) throws IOException {public static boolean contentEquals(Reader input1, Reader input2) throws IOException {public static boolean contentEqualsIgnoreEOL(Reader input1, Reader input2) throws IOException {******************
跳过流public static long skip(InputStream input, long toSkip) throws IOException {public static long skip(ReadableByteChannel input, long toSkip) throws IOException {public static long skip(Reader input, long toSkip) throws IOException {public static void skipFully(InputStream input, long toSkip) throws IOException {public static void skipFully(ReadableByteChannel input, long toSkip) throws IOException {public static void skipFully(Reader input, long toSkip) throws IOException {********************
读取流数据public static int read(Reader input, char[] buffer, int offset, int length) throws IOException {public static int read(Reader input, char[] buffer) throws IOException {public static int read(InputStream input, byte[] buffer, int offset, int length) throws IOException {public static int read(InputStream input, byte[] buffer) throws IOException {public static int read(ReadableByteChannel input, ByteBuffer buffer) throws IOException {public static void readFully(Reader input, char[] buffer, int offset, int length) throws IOException {public static void readFully(Reader input, char[] buffer) throws IOException {public static void readFully(InputStream input, byte[] buffer, int offset, int length) throws IOException {public static void readFully(InputStream input, byte[] buffer) throws IOException {public static byte[] readFully(InputStream input, int length) throws IOException {public static void readFully(ReadableByteChannel input, ByteBuffer buffer) throws IOException {

FileUtils:文件操作

public class FileUtils {**************
获取文件、目录public static File getFile(File directory, String... names) {public static File getFile(String... names) {public static String getTempDirectoryPath() {public static File getTempDirectory() {public static String getUserDirectoryPath() {public static File getUserDirectory() {***************
获取文件输入流public static FileInputStream openInputStream(File file) throws IOException {public static FileOutputStream openOutputStream(File file) throws IOException {public static FileOutputStream openOutputStream(File file, boolean append) throws IOException {****************
列出文件、目录public static Collection<File> listFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {public static Collection<File> listFiles(File directory, String[] extensions, boolean recursive) {public static Collection<File> listFilesAndDirs(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {public static Iterator<File> iterateFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {public static Iterator<File> iterateFiles(File directory, String[] extensions, boolean recursive) {public static Iterator<File> iterateFilesAndDirs(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {*******************
判断文件是否相等public static boolean contentEquals(File file1, File file2) throws IOException {public static boolean contentEqualsIgnoreEOL(File file1, File file2, String charsetName) throws IOException {******************
url、文件转换public static File toFile(URL url) {public static File[] toFiles(URL[] urls) {public static URL[] toURLs(File[] files) throws IOException {static String decodeUrl(String url) {****************
文件、目录复制操作public static void copyFile(File srcFile, File destFile) throws IOException {public static void copyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {public static long copyFile(File input, OutputStream output) throws IOException {public static void copyFileToDirectory(File srcFile, File destDir) throws IOException {public static void copyFileToDirectory(File srcFile, File destDir, boolean preserveFileDate) throws IOException {public static void copyDirectory(File srcDir, File destDir) throws IOException {public static void copyDirectory(File srcDir, File destDir, boolean preserveFileDate) throws IOException {public static void copyDirectory(File srcDir, File destDir, FileFilter filter) throws IOException {public static void copyDirectory(File srcDir, File destDir, FileFilter filter, boolean preserveFileDate) throws IOException {public static void copyDirectoryToDirectory(File srcDir, File destDir) throws IOException {public static void copyToDirectory(File src, File destDir) throws IOException {public static void copyToDirectory(Iterable<File> srcs, File destDir) throws IOException {*****************
url、字节流、文件操作public static void copyURLToFile(URL source, File destination) throws IOException {public static void copyURLToFile(URL source, File destination, int connectionTimeout, int readTimeout) throws IOException {public static void copyInputStreamToFile(InputStream source, File destination) throws IOException {public static void copyToFile(InputStream source, File destination) throws IOException {******************
删除目录public static void deleteDirectory(File directory) throws IOException {public static boolean deleteQuietly(File file) {******************
目录判断public static boolean directoryContains(File directory, File child) throws IOException {public static void cleanDirectory(File directory) throws IOException {*******************
读取文件操作public static String readFileToString(File file, Charset encoding) throws IOException {public static String readFileToString(File file, String encoding) throws IOException {public static byte[] readFileToByteArray(File file) throws IOException {public static List<String> readLines(File file, Charset encoding) throws IOException {public static List<String> readLines(File file, String encoding) throws IOException {public static LineIterator lineIterator(File file, String encoding) throws IOException {public static LineIterator lineIterator(File file) throws IOException {***************
输出到文件public static void writeStringToFile(File file, String data, Charset encoding) throws IOException {public static void writeStringToFile(File file, String data, String encoding) throws IOException {public static void writeStringToFile(File file, String data, Charset encoding, boolean append) throws IOException {public static void writeStringToFile(File file, String data, String encoding, boolean append) throws IOException {public static void write(File file, CharSequence data, Charset encoding) throws IOException {public static void write(File file, CharSequence data, String encoding) throws IOException {public static void write(File file, CharSequence data, Charset encoding, boolean append) throws IOException {public static void write(File file, CharSequence data, String encoding, boolean append) throws IOException {public static void writeByteArrayToFile(File file, byte[] data) throws IOException {public static void writeByteArrayToFile(File file, byte[] data, boolean append) throws IOException {public static void writeByteArrayToFile(File file, byte[] data, int off, int len) throws IOException {public static void writeByteArrayToFile(File file, byte[] data, int off, int len, boolean append) throws IOException {public static void writeLines(File file, String encoding, Collection<?> lines) throws IOException {public static void writeLines(File file, String encoding, Collection<?> lines, boolean append) throws IOException {public static void writeLines(File file, Collection<?> lines) throws IOException {public static void writeLines(File file, Collection<?> lines, boolean append) throws IOException {public static void writeLines(File file, String encoding, Collection<?> lines, String lineEnding) throws IOException {public static void writeLines(File file, String encoding, Collection<?> lines, String lineEnding, boolean append) throws IOException {public static void writeLines(File file, Collection<?> lines, String lineEnding) throws IOException {public static void writeLines(File file, Collection<?> lines, String lineEnding, boolean append) throws IOException {****************
强制删除创建文件、目录public static void forceDelete(File file) throws IOException {public static void forceDeleteOnExit(File file) throws IOException {public static void forceMkdir(File directory) throws IOException {public static void forceMkdirParent(File file) throws IOException {****************
移动文件目录public static void moveDirectory(File srcDir, File destDir) throws IOException {public static void moveDirectoryToDirectory(File src, File destDir, boolean createDestDir) throws IOException {public static void moveFile(File srcFile, File destFile) throws IOException {public static void moveFileToDirectory(File srcFile, File destDir, boolean createDestDir) throws IOException {public static void moveToDirectory(File src, File destDir, boolean createDestDir) throws IOException {****************
文件目录大小public static long sizeOf(File file) {public static BigInteger sizeOfAsBigInteger(File file) {public static long sizeOfDirectory(File directory) {public static BigInteger sizeOfDirectoryAsBigInteger(File directory) {*****************
文件新旧public static boolean isFileNewer(File file, File reference) {public static boolean isFileNewer(File file, Date date) {public static boolean isFileNewer(File file, long timeMillis) {public static boolean isFileOlder(File file, File reference) {public static boolean isFileOlder(File file, Date date) {public static boolean isFileOlder(File file, long timeMillis) {******************
其他方法public static void touch(File file) throws IOException {  public static File[] convertFileCollectionToFileArray(Collection<File> files) {public static boolean waitFor(File file, int seconds) {public static String byteCountToDisplaySize(BigInteger size) {public static String byteCountToDisplaySize(long size) {public static long checksumCRC32(File file) throws IOException {public static Checksum checksum(File file, Checksum checksum) throws IOException {

****************************

示例

*********************

controller 层

HelloController

@RestController
public class HelloController {@Value("classpath:/static/file/hello.txt")private Resource resource;@Value("classpath:/static/file/hello.txt")private File file;@Value("http://www.baidu.com")private Resource resource2;@Value("http://www.baidu.com")private URL url;@RequestMapping("/hello2")public String hello2() throws Exception{System.out.println("hello2 输出:");System.out.println(IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8)+"\n");return "success 2";}@RequestMapping("/hello3")public String hello3() throws Exception{System.out.println("hello3 输出:");System.out.println(FileUtils.readFileToString(file,StandardCharsets.UTF_8)+"\n");return "success 3";}@RequestMapping("/hello4")public String hello4() throws Exception{System.out.println("hello4 输出:");System.out.println(IOUtils.toString(resource2.getInputStream(), StandardCharsets.UTF_8));System.out.println(IOUtils.toString(url, StandardCharsets.UTF_8));return "success 4";}
}

*************************

控制台输出

hello2 输出:
hello world
hello world 2
hello world 3
hello world 4hello3 输出:
hello world
hello world 2
hello world 3
hello world 4hello4 输出:
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html><!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

springboot 常用工具(IOUtils、FileUtils)相关推荐

  1. apache-commons 常用工具类

    引用包说明 本文引用的所有包如下 <dependency><groupId>org.apache.commons</groupId><artifactId&g ...

  2. (转)JAVA 十六个常用工具类

    (转)JAVA 十六个常用工具类 一. org.apache.commons.io.IOUtils closeQuietly 关闭一个IO流.socket.或者selector且不抛出异常.通常放在f ...

  3. Java常用工具类库

    Java常用工具类库 1. java自带工具方法 2. apache commons工具类库 2.1 commons-lang,java.lang的增强版 2.2 commons-collection ...

  4. JAVA常用工具类(实用高效)

    JAVA常用工具类(根据GITHUB代码统计) 从Google你能搜索到大量的关于Struts,Spring,Hibernate,iBatis等比较大的框架的资料,但是很少有人去关注一些小的工具包,但 ...

  5. Java 常用工具类整理

    目录 第一部分:常用的16个工具类 第二部分:java开发常用工具类(正则校验) 第一部分:常用的16个工具类 一.org.apache.commons.io.IOUtils 1.closeQuiet ...

  6. java escape工具类_java开发常用工具类

    在Java中,,工具类定义了一组公共方法.你把你的类继承这些类或者实现这些接口,就可以使用这些类的方法了.下面给大家介绍一下十六种最常用的java开发常用工具类. 一. org.apache.comm ...

  7. android 快速开发常用工具类,实例详解Android快速开发工具类总结

    一.日志工具类 Log.java public class L { private L() { /* 不可被实例化 */ throw new UnsupportedOperationException ...

  8. curl命令java_让 Bug 无处藏身,Java 线上问题排查思路、常用工具

    本文总结了一些常见的线上应急现象和对应排查步骤和工具.分享的主要目的是想让对线上问题接触少的同学有个预先认知,免得在遇到实际问题时手忙脚乱. 只不过这里先提示一下.在线上应急过程中要记住,只有一个总体 ...

  9. java file ip_java常用工具类 IP、File文件工具类

    本文实例为大家分享了java常用工具类的具体实现代码,供大家参考,具体内容如下 IP工具类 package com.jarvis.base.util; import java.io.IOExcepti ...

最新文章

  1. 给你的开源项目加一个绶带吧
  2. opencv亚像素点检测
  3. 全球及中国肥料市场格局展望与十四五经营效益分析报告2022版
  4. java 文件大小统计工具类_Java获取文件大小,文件夹内文件个数的工具类
  5. 为什么中小企业选择 SAP Business One?
  6. 2018.8.2 python中is和==的区别
  7. hbuildx打包成apk_基于HBuilder将H5站点打包成app
  8. python中eof什么意思_python eof表什么意思
  9. VC6.0多行注释快捷键的设置
  10. Spark Streaming官网重点整理
  11. 成功解决 zsh: command not found
  12. TCP报文头部结构详解和作用解析
  13. 那些漂亮有创意的思维导图真的更吸引人吗?
  14. 超酷的iOS动画集合
  15. python不重复排列组合_python解决排列组合
  16. 盘点中美自动驾驶卡车领域公司, 先进的技术和落地的场景
  17. JAVA判断当前日期是否是工作日,还是节假日
  18. 无https证书调用摄像头以及精伦读卡器IDR210-1调用安装
  19. 国信证券学习系列(7)
  20. HTML-一些自己不常用但很有用的标签

热门文章

  1. SAP GUI 740 windows 免费下载
  2. SQL注入漏洞的攻击与防御
  3. 排坑:运行win32com.client.Dispatch('Word.Application')和docx.Documents.Open()报错
  4. DB9 在 RS232 通讯上的应用接法详解
  5. 2021年上半年系统集成项目管理工程师上午试题参考解析(三)
  6. Linux命令·ps
  7. 服务器显示检测不到内存,服务器检测不到内存
  8. FMCW激光雷达,未来已来
  9. 设置伪静态或者生成html,网站要设置伪静态,需先弄清楚自己的网站环境!
  10. win7查看Cookie存放的位置