如何在byte []中传递charcter以复制到文件中 [英] how to pass charcter in byte [] to copy into file
问题描述
我想将字符串附加到文件的下面是代码*
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 astring
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屋!