如何在byte []中传递charcter以复制到文件中 [英] how to pass charcter in byte [] to copy into file

查看:116
本文介绍了如何在byte []中传递charcter以复制到文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将字符串附加到文件的下面是代码*

i get error



byte [] test =%PDF -1.5; //错误在这里

任何方式通过这个?



fis = new FileInputStream(" sdcard / pdf / a.pdf");

fos = new FileOutputStream(" sdcard / pdf / b.pdf");

fastcopy(fis,fos);





以下是代码

public static void fastcopy(InputStream is,OutputStream os)抛出IOException {

byte [] bytes = new byte [64];

int numBytes;

byte [] test =%PDF-1.5; //错误在这里< br $>


os.write(test);

while((numBytes = is.read(bytes))!= -1){



os.write(bytes,0,numBytes);

}

os.flush();

os.close();

is.close();



}

i want to append string into begning of file below is code *
i get error

byte []test="%PDF-1.5";// error here
any way to pass this ??

fis = new FileInputStream("sdcard/pdf/a.pdf");
fos = new FileOutputStream("sdcard/pdf/b.pdf");
fastcopy(fis, fos);


below is code
public static void fastcopy(InputStream is, OutputStream os) throws IOException {
byte[] bytes = new byte[64];
int numBytes;
byte []test="%PDF-1.5";// error here

os.write(test);
while ((numBytes = is.read(bytes)) != -1) {

os.write(bytes, 0, numBytes);
}
os.flush();
os.close();
is.close();

}

推荐答案

您不能指定 st响铃到没有转换的字节[]。



阅读以下内容:http://developer.android.com/training/basics/data-storage/files.html [ ^ ]

http://developer.android.com/reference/java/io/StringWriter.html [ ^ ]
You can't assign a string to a byte[] without conversion.

Read the following : http://developer.android.com/training/basics/data-storage/files.html[^]
http://developer.android.com/reference/java/io/StringWriter.html[^]


这篇关于如何在byte []中传递charcter以复制到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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