A glace on Java Stream

本文探讨了Java中文件操作的两种类型:文本文件和二进制文件,并详细介绍了流(Stream)的概念及其在文件读写中的应用。通过具体实例展示了如何建立远程资源与本地资源之间的连接,包括使用WebDAV服务作为数据源流以及FTP资源获取的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     Today, I just finish the file operation on webdav. On the first eye, it will be more efficient for the proxy just set url to the client. But  it trun out not more support by Java, may it has another swift operation, but I havenot find it.
     Now, I just want to talk about the Stream in Java. After the translation I feel a little familiar will Stream, but it turn out so easy and simple, and have no help to transfer. In Java, there has two file type, one is the text file, the other is binary file. They just operate in a diffrent way. We could read textfile one word by word or line by line, and then some class help us to tranform the to the original Java object, where the write method has  the same way. On the other hand, the binary just read or write in a streaming with byte code. And byte array will transfter to the orignal object, we also could use Serializable interface to transform our Object into byte code.
     And what I want to do just build a connection betweent the destination resource and local resource. From example we invoke a webDave Service and use it as the from stream and wrap as InputStream, and the request from the client just invoke the response.getOutputStreaming() to write stream. The transfer betweent ftp and http in the same way. I use org.apache.commons.net.ftp to realize the ftp resource get, and use sarding to transfer the resource.
In the end, I find make a fool mistake, and I want to share it with you. I use a buffer(byte[1024*2]) to buffer the stream, and I encluspe the software both inputstream and outputstream. But there is alway something wrong with .gz files, and there is no problem with other file type. With the great seache engine, I found I just forget to statement the length of the buffer, and just the last portion will goes wrong, so it change it into read(buffer,0, buffere.lenght), everything work right. 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值