需要一种简单的方法将字符串转换为文件 [英] need an easy way convert a string to file

查看:83
本文介绍了需要一种简单的方法将字符串转换为文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我读取了一个文件并将其转换为字符串,然后用霍夫曼​​编码后,将该字符串写入另一个文件(压缩文件)!
现在,当我解压缩文件时,我可以到达第一个字符串
但是,当将其写入文件时,它不是第一个文件:|
我该怎么办?

但是我应该说它可以正确地用于文本文件,但是
不适用于图片!:|

例子:
输入文件:

input = new FileInputStream( "f:/testpic.bmp" );


输出文件:

BitOutputStream fop2 = new BitOutputStream("f:/is.oli");



当我读取输出文件并到达第一个字符串时,然后将其写入新文件
它不是第一个:|

请帮助
谢谢!

解决方案

再次向我问好
我前几天提到过,在编码霍夫曼编码的过程中,忘记了以字符串的方式思考,以字节流的方式思考.

您的图片中可能有很多零.如果将其作为字符串处理,则零表示字符串结尾".

这意味着:您的程序可以很好地处理字符串...因此您必须用字节数组,字节[] [(:
)替换字符串(更好的流)
问候


hi
i read a file and convert it to string, and then after some en-coding with huffman, i write that string, to another file(compressed file)!
now when i decompress the file i can reach to first string
but when write it to a file its not the first file :|
what should i do?

but i should say that it works for text file correctly but
not for pictures !:|

example :
input file :

input = new FileInputStream( "f:/testpic.bmp" );


out put file:

BitOutputStream fop2 = new BitOutputStream("f:/is.oli");



when i read the output file and reach the first string, then write it to new file
its not the first :|

please help
thanks!

解决方案

Hi again me
I mentioned before some days, while coding Huffman forget thinking in string, think in stream of bytes.

Your picture will have probably a lot of zero''s in it. If you handle this as string, then a Zero means "end of string".

It means: Your program works fine for string...so you have to replace string by array (better stream) of bytes, byte[] :(

Regards


这篇关于需要一种简单的方法将字符串转换为文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆