org.apache.commons.io.IOUtils
1、IOUtils.toString(InputStream input)
protected boolean writeEJBJar(String path, WebServiceProject project){ String ejbJar = null; try { ejbJar = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("META-INF/ws/ejb-jar.comm.template")); logger.debug("get template pass..."); ejbJar = String.format(ejbJar, project.getName()); logger.debug("template format :\n" + ejbJar); FileUtils.writeStringToFile(new File(path), ejbJar, "UTF-8"); logger.debug("write " + path + " to harddrive pass..."); } catch (Exception e) { e.printStackTrace(); logger.error("writeBuild error : " + e.getMessage()); return false; } return true; }
源码:
//注意此处用的StringWriter来实现字符输出展示 public static String toString(InputStream input) throws IOException { StringWriter sw = new StringWriter(); copy(input, sw); return sw.toString(); }
public static void copy(InputStream input, Writer output) throws IOException { InputStreamReader in = new InputStreamReader(input); copy(in, output); } public static int copy(Reader input, Writer output) throws IOException { long count = copyLarge(input, output); if (count > Integer.MAX_VALUE) { return -1; } return (int) count; }
/** * The default buffer size to use. */ private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; public static long copyLarge(Reader input, Writer output) throws IOException { char[] buffer = new char[DEFAULT_BUFFER_SIZE]; long count = 0; int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; } return count; }
InputStream => InputStreamReader => Reader
StringWriter => Writer
注意此处用的StringWriter来实现字符输出展示
获取异常堆栈信息,也是使用StringWriter展示,如:
import java.io.PrintWriter; import java.io.StringWriter; public class ExceptionUtils { public static String getStackTrace(Throwable t) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); try { t.printStackTrace(pw); return sw.toString(); } finally { pw.close(); } } }
。。
相关推荐
java组件开发(12) IOUtils、FileUtils
org.apache.commons的jar包 IOUtils jar
六祎:获取类路径下的资源教程,https://blog.csdn.net/qq_41086359/article/details/101646178 教程所需的 jar包
org.apache.commons的所有jar包:commons-io-1.4.jar、commons-fileupload-1.2.1.jar等等
项目中需要 org.apache.commons.io.IOUtils的可以下载此包,fileupload组件依赖的commons-io组件
源码包
资源内容:工欲善其事必先利其器,本资源内容为Java开发常用工具类打包,如BeanUtil,ArrayUtil,HtmlUtil,ClassUtil,DateUtil,FileUtil,FontUtil,ImageUtil,IOUtil, IPUtil, MapUtil,MailUtil, NumberUtil,...
FileCtrl, StrUtils, Masks, Vcl.OleCtrls, SHDocVw, IOUtils; procedure SaveTreeViewExplandState(TreeView: TTreeView; FileName: string); procedure LoadTreeViewExplandState(TreeView: TTreeView; FileName...
java_IO操作_(读写、追加、删除、移动、复制、修改)
commons-io 是 Apache 开源基金组织提供的一组有关 IO 操作的类库,可以挺提高 IO 功能开发的效率。commons-io 工具包提供了很多有关 IO 操作的类
用于dubbo项目pom,使用zookeeper进行注册时可以进行使用
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod;...import org.apache.commons.io.IOUtils;
- 由第三方研发的工具类 - 要使用commons-io工具包,就需要先从第三方下载该工具包 ...IOUtils类: 复制单个文件(文件对文件) FileUtils工具类: 复制目录或文件(多个文件) commons-io可以简化IO复制文件的操作
相关博文 NO.63 [file]IO常用工具类IOUtils(Java读文件、写文件、打Zip包)USB接口IC读写器oem软件_AB密码完整解决方案/读写卡测试程序及源代码/c#2003源代码自己动手写聊天软件推荐个软件:wxHexEditor,基于GPL...
图片压缩,阿里巴巴SimpleImage ... IOUtils.closeQuietly(outStream); if (wr != null) { try { wr.dispose(); //释放simpleImage的内部资源 } catch (SimpleImageException ignore) { // skip ... } } } }
IOUtils IOUtils MD5 MD5 MiscUtils 设备信息的获取 NetWorkUtils 网络状态 PhoneUtil 手机组件调用工具类 PreferencesUtils sp工具类 RandomUtils 随机数工具类 RecorderControl 录音工具类 SerializeUtils ...
public void code(HttpServletRequest request, HttpServletResponse response) throws IOException{ String[] tableNames = new String[]{};... IOUtils.write(data, response.getOutputStream()); }
BitmapUtils、FileUtils、IOUtils、PhotoUtils、StorageUtils。用于图片、文件、Bitmap、IO流之间的转换 > log > -- LogUtils。Log工具类,可控制Log输出开关、保存Log到文件、过滤输出等级 > network > -- 用于判断...
打开IOUtils的api文档,我们发现它的方法大部分都是重载的。所以,我们理解它的方法并不是难事。因此,对于方法的用法总结如下: 1. buffer方法:将传入的流进行包装,变成缓冲流。并可以通过参数指定缓冲大小。 2...
java后端代码: ... IOUtils.copy(inputStream, response.getOutputStream()); response.flushBuffer(); System.out.println("输出成功!"); } HTML前端接response收流: type="video/mp4"> </video>