**
flow into streams and low-level flow: Common low-level stream file input stream (FileInputStream) and file output streams (FileOutputStream), a stream of bytes, read and write in units of characters. Advanced Stream has character stream, the stream conversion, buffering character stream, the unit character reader, wherein java.io.Reader: the top-level parent character input stream, java.io.Writer: top-level parent character output stream
1. FileOutputStream file output stream, role: to create a file and write to the file. FileOutputStream fos = new FileOutputStream ( "xxx.txt "), created xxx.txt. Then write, Note: only input byte file, so
we need to use str.getBytes (), to give a set of byte array, fos.write (data), wherein data for the array.
java.io.FileNotFoundException Import;
Import java.io.FileOutputStream;
Import java.io.IOException;
Import java.io.UnsupportedEncodingException;
Import javax.imageio.stream.FileCacheImageOutputStream;
public class FOSDemo {
public static void main (String [] args ) throws IOException {
/ *
* fOS is created by default is covered writes
* fOS will first of all file data (if data)
* delete, rewrite began to write
/
FileOutputStream fos =
new new FileOutputStream ( "fos.txt");
string str = "I love you Tiananmen";
/
* file can only input bytes
* String-> byte []
* byte getBytes []
* the current string in accordance with the system default character set conversion
* as a set of byte
* byte getBytes (string CSN)
* according to a given set of the current character string into
* a group of bytes
* /
Byte [] = Data str.getBytes ( "UTF-. 8");
fos.write (Data);
System.out.println ( "Input completed!");
Fos.close ();
}
}
2.FileInputStream: file input stream of bytes read from the file.
import java.io.UnsupportedEncodingException;
/**
- java.io.FileInputStream
- File input stream is a stream of low-level, from a file for
- Read byte
- War memories @author heart rhythm
*/
public class FileInputStream {
public FileInputStream(String string) {
}
public static void main(String[] args) throws UnsupportedEncodingException {
FileInputStream fis
=new FileInputStream("fos.txt");
byte[] data=new byte[100];
int len =fis.read(data);//实际读到的长度
String str=new String(
data,0,len,"UTF-8"
);//byte->String
System.out.println(str);
fis.close();
}
void close() {
// TODO Auto-generated method stub
}
int read(byte[] data) {
return 0;
}
}