Byte[] to InputStream or OutputStream

byte[] source = ...;
ByteArrayInputStream bis = new ByteArrayInputStream(source);
// read bytes from bis ...

ByteArrayOutputStream bos = new ByteArrayOutputStream();
// write bytes to bos ...
byte[] sink = bos.toByteArray();

file path to inputstream:

InputStream is;

try {
is = new FileInputStream(“c://filename”);

is.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return is;


File file=new File(“c:\\abc.txt”);
InputStream is = new FileInputStream(file);
or

InputStream is = new FileInputStream(“c:\\abc.txt”);

 

相關文章

寫留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *