【文件操作相关】

2017-09-13  本文已影响1人  0xC

说明,测试机型为小米Note4,miui系统

getFileDir

File fileDir = getFileDir();
tv1.stText(fileDir.getPath());

OutputStream&openFileOutput

OutputStream outStream = openFileOutput("test.dat",MODE_PRIVATE);
String contents = "hello this a segment of test code,welcome";
outStream.write(contents.getBytes());
outStream,flush();
outStream.close();

OutputStream outStream = openFileOutput("test.dat",MODE_PRIVATE);
建立输出流
输出流,一个到磁盘文件的映射
文件,磁盘上的一段区域

outStream,flush();
客户端主动将输出流写到磁盘上

InputStream&ByteArrayOutputStream

InputStream inStream = new InputStream("test.dat");
byte[] buffer = new byte[1024];
int len = -1;

ByteArrayOutputStream baos = new ByteArrayOutputStream();
while((len = inStream.readBuffer(buffer)) != -1){
     baos.write(buffer,0,len); 
}

inStream.close();
baos.close();

we generate baos,a byteArray which contains data from file.

InputStream inStream = newInputStream("test.dat");
建立文件输入流,数据入端为磁盘文件

len = inStream.readBuffer(buffer)
确认输入流的终端,即一段内存区域,完成数据流的读取与写入

上一篇 下一篇

猜你喜欢

热点阅读