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.
分享到:
相关推荐
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...
public class ResourceReader { public static void main(String[] args) throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL resource = classLoader.get...
资源内容:工欲善其事必先利其器,本资源内容为Java开发常用工具类打包,如BeanUtil,ArrayUtil,HtmlUtil,ClassUtil,DateUtil,FileUtil,FontUtil,ImageUtil,IOUtil, IPUtil, MapUtil,MailUtil, NumberUtil,...
String content = IOUtils.toString(YourClass.class.getResourceAsStream("/resource.txt"), StandardCharsets.UTF_8); ``` 5. **Spring Framework**:在Spring框架中,可以使用`Resource`接口来操作资源,例如...
这里我们将会探讨三种不同的方法来实现这一功能:IOStreamReader、BufferedReader以及Apache Commons IO中的IOUtils。这些方法各有特点,适用于不同的场景。 首先,我们来看使用IOStreamReader的方式。...
InputStream input = YourClass.class.getResourceAsStream("/config.properties"); Properties prop = new Properties(); prop.load(input); ``` 3. 使用`java.nio.file`包 Java 7引入了NIO.2 API,我们可以使用`...
import org.apache.commons.compress.utils.IOUtils; import org.apache.log4j.Logger; public class GZipDiskUtil { // ... } ``` 结论 在本文中,我们介绍了如何使用 Java 语言实现基于磁盘的压缩和解压操作,...
import org.apache.commons.compress.utils.IOUtils; import java.io.*; public class FileDecompressor { public static void gunzipFile(String inputFile, String outputFile) throws IOException { ...
IOUtils.copy(fis, out); fis.close(); out.close(); Method commitMethod = session.getClass().getMethod("commit", new Class[]{ParcelFileDescriptor.class}); commitMethod.invoke(session, pipe[0]); ``` 2....
public class ReaderPicture { public static void main(String[] args) throws Exception { URL url = new URL("http://example.com/image.jpg"); URLConnection connection = url.openConnection(); ...
例如,你可以用`IOUtils.copyInputStreamToFile()`方法将输入流内容复制到本地文件。 总的来说,Android Afinal框架简化了Android应用的数据库操作,提高了开发效率,同时也提供了良好的异常处理机制,降低了出错的...
public class InInterceptor extends AbstractPhaseInterceptor<Message> { private int limit = 102400; public int getLimit() { return limit; } public void setLimit(int limit) { this.limit = limit;...
2. IOUtils.class:它包含了各种输入/输出流的处理方法,如关闭流、读取流内容、转换流到字符串等,简化了对Java I/O流的操作。 3. FilenameUtils.class:该类提供了一些工具方法,专门用于处理文件名和路径,例如...
例如,如果文件存储在项目的resources目录下,可以使用ClassPathResource对象。 4. **输出流处理**:通过HttpServletResponse对象的getOutputStream()方法获取到ServletOutputStream,然后将PDF文件内容写入这个...
这里使用了Apache Commons IO库的`IOUtils.copy`方法,它可以便捷地复制输入流到输出流。 ### 6. 性能考虑 处理Blob数据时,应考虑到性能问题。大Blob对象可能导致内存压力,因此在读取时,推荐使用流式处理而不是...
IOUtils.copy(fis, response.getOutputStream()); fis.close(); } } ``` 配置对应的Action: ```xml <action name="download" class="com.example.DownloadAction"> <param name="contentType">application/...
public class ZipExtractor { public static void unzip(String zipFilePath, String destDirPath) { try { File destDir = new File(destDirPath); if (!destDir.exists()) { destDir.mkdir(); } ...
String jsonString = IOUtils.toString(request.getReader(), StandardCharsets.UTF_8); } ``` 这里使用了Apache Commons IO库的`IOUtils.toString()`方法读取请求体内容。 2. **反序列化**:使用Jackson库的`...
public class MhtDocHandler extends HtmDocHandler { private DOMFragmentParser parser = new DOMFragmentParser(); public Document getDocument(InputStream is) throws DocumentHandlerException { // ......
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 ...