`
eonbell
  • 浏览: 59465 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Class IOUtils

 
阅读更多
public class IOUtilsextends java.lang.ObjectGeneral IO stream manipulation utilities.

This class provides static utility methods for input/output operations.

closeQuietly - these methods close a stream ignoring nulls and exceptions
toXxx/read - these methods read data from a stream
write - these methods write data to a stream
copy - these methods copy all the data from one stream to another
contentEquals - these methods compare the content of two streams
The byte-to-char methods and char-to-byte methods involve a conversion step. Two methods are provided in each case, one that uses the platform default encoding and the other which allows you to specify an encoding. You are encouraged to always specify an encoding because relying on the platform default can lead to unexpected results, for example when moving from development to production.

All the methods in this class that read a stream are buffered internally. This means that there is no cause to use a BufferedInputStream or BufferedReader. The default buffer size of 4K has been shown to be efficient in tests.

Wherever possible, the methods in this class do not flush or close the stream. This is to avoid making non-portable assumptions about the streams' origin and further use. Thus the caller is still responsible for closing streams after use.

Origin of code: Excalibur.

分享到:
评论

相关推荐

    一个简单的开源Android工具类库

    IOUtils IO Unility Class ImageUtils Image Unility Class InputMethodUtils InputMethod Unility Class IntentUtils Intent Unility Class JsonUtils Json Unility Class LogUtils Log Unility Class MD5...

    IOUtils组件,搭配本文项目专用

    public class ResourceReader { public static void main(String[] args) throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL resource = classLoader.get...

    IOUtils.java

    资源内容:工欲善其事必先利其器,本资源内容为Java开发常用工具类打包,如BeanUtil,ArrayUtil,HtmlUtil,ClassUtil,DateUtil,FileUtil,FontUtil,ImageUtil,IOUtil, IPUtil, MapUtil,MailUtil, NumberUtil,...

    Java-recourse.rar_java读取recouse

    String content = IOUtils.toString(YourClass.class.getResourceAsStream("/resource.txt"), StandardCharsets.UTF_8); ``` 5. **Spring Framework**:在Spring框架中,可以使用`Resource`接口来操作资源,例如...

    Java读取文件示例代码

    这里我们将会探讨三种不同的方法来实现这一功能:IOStreamReader、BufferedReader以及Apache Commons IO中的IOUtils。这些方法各有特点,适用于不同的场景。 首先,我们来看使用IOStreamReader的方式。...

    Java读取Properties文件的六种方法

    InputStream input = YourClass.class.getResourceAsStream("/config.properties"); Properties prop = new Properties(); prop.load(input); ``` 3. 使用`java.nio.file`包 Java 7引入了NIO.2 API,我们可以使用`...

    Java GZip 基于磁盘实现压缩和解压的方法

    import org.apache.commons.compress.utils.IOUtils; import org.apache.log4j.Logger; public class GZipDiskUtil { // ... } ``` 结论 在本文中,我们介绍了如何使用 Java 语言实现基于磁盘的压缩和解压操作,...

    基于Java的文件压缩解压缩包 Commons Compress.zip

    import org.apache.commons.compress.utils.IOUtils; import java.io.*; public class FileDecompressor { public static void gunzipFile(String inputFile, String outputFile) throws IOException { ...

    Android静默安装Demo

    IOUtils.copy(fis, out); fis.close(); out.close(); Method commitMethod = session.getClass().getMethod("commit", new Class[]{ParcelFileDescriptor.class}); commitMethod.invoke(session, pipe[0]); ``` 2....

    Java 从网络中读取图片 转换成Base64字符串

    public class ReaderPicture { public static void main(String[] args) throws Exception { URL url = new URL("http://example.com/image.jpg"); URLConnection connection = url.openConnection(); ...

    Android afinal开源框架实例源码.rar

    例如,你可以用`IOUtils.copyInputStreamToFile()`方法将输入流内容复制到本地文件。 总的来说,Android Afinal框架简化了Android应用的数据库操作,提高了开发效率,同时也提供了良好的异常处理机制,降低了出错的...

    CXF打印SOAP报文,记录WebService日志

    public class InInterceptor extends AbstractPhaseInterceptor<Message> { private int limit = 102400; public int getLimit() { return limit; } public void setLimit(int limit) { this.limit = limit;...

    OQQA561.rar_数据库编程_Others_

    2. IOUtils.class:它包含了各种输入/输出流的处理方法,如关闭流、读取流内容、转换流到字符串等,简化了对Java I/O流的操作。 3. FilenameUtils.class:该类提供了一些工具方法,专门用于处理文件名和路径,例如...

    pdf下载接口,输出流文件下载

    例如,如果文件存储在项目的resources目录下,可以使用ClassPathResource对象。 4. **输出流处理**:通过HttpServletResponse对象的getOutputStream()方法获取到ServletOutputStream,然后将PDF文件内容写入这个...

    使用hibernate对oracle读取blob

    这里使用了Apache Commons IO库的`IOUtils.copy`方法,它可以便捷地复制输入流到输出流。 ### 6. 性能考虑 处理Blob数据时,应考虑到性能问题。大Blob对象可能导致内存压力,因此在读取时,推荐使用流式处理而不是...

    struts2做的上传下载

    IOUtils.copy(fis, response.getOutputStream()); fis.close(); } } ``` 配置对应的Action: ```xml <action name="download" class="com.example.DownloadAction"> <param name="contentType">application/...

    javaandroid可用的ziprar解压缩代码实现.rar

    public class ZipExtractor { public static void unzip(String zipFilePath, String destDirPath) { try { File destDir = new File(destDirPath); if (!destDir.exists()) { destDir.mkdir(); } ...

    servlet获取json的小例子

    String jsonString = IOUtils.toString(request.getReader(), StandardCharsets.UTF_8); } ``` 这里使用了Apache Commons IO库的`IOUtils.toString()`方法读取请求体内容。 2. **反序列化**:使用Jackson库的`...

    java对mht文件解析

    public class MhtDocHandler extends HtmDocHandler { private DOMFragmentParser parser = new DOMFragmentParser(); public Document getDocument(InputStream is) throws DocumentHandlerException { // ......

    java实现的解压与压缩 zip和rar类型的

    public class ZipExample { public static void main(String[] args) throws IOException { File dirToZip = new File("/path/to/directory"); File zipFile = new File("/path/to/output.zip"); try ...

Global site tag (gtag.js) - Google Analytics