, - , , . ByteArrayInputStream , . , byte[]. , read(), .
byte[] bytes ={1,-1,0};
ByteArrayInputStream in =new ByteArrayInputStream(bytes);
int readedInt =in.read(); //readedInt=1
readedInt=in.read();//readedInt=255
readedInt=in.read();//readedInt=0
, ByteArrayOutputStream.
byte[], , write(). , toByteArray().
ByteArrayOutputStream out =new ByteArrayOutputStream();
out.write(10);
out.write(11);
byte[] bytes =out.toByteArray();
FileInputStream FileOutputStream
FileInputStream .
, .
FileOutputStream. , , , . , , FileOutputStream .
byte[] bytesToWrite ={1,2,3}; byte[] bytesReaded =new byte[10]; String fileName ="d:\\test.txt";
//
//
try {
FileOutputStream outFile =new FileOutputStream(fileName);
outFile.write(bytesToWrite); // outFile.close();
FileInputStream inFile =new FileInputStream(fileName);
int bytesAvailable =inFile.available(); // int count =inFile.read(bytesReaded,0,bytesAvailable); inFile.close();}
catch (FileNotFoundException e){
System.out.println(" :"+fileName);} catch (IOException e){
System.out.println(" /:"+e.toString());}
FileInputStream available() , , . , - available() , .
-
, / - , , , . . , , . ( .) - . , - /. java.io . -, , , .
|
|
java.io / FilterInputStream ( ) FilterOutputStream ( ). / - InputStream OutputStream . InputStream protected. . ( ), . .
- BuffereInputStream BufferedOutputStream. , , . BufferedInputStream , . , ( read()) ( skip()), , . BufferedInputStream mark() reset(). InputStream, IOException. mark() reset() , , mark(), , .
BufferedOutputStream - , / . . , , , . - flush(). ( close()). , .
String fileName ="d:\\file1";
InputStream inStream =null;
OutputStream outStream =null; //
long timeStart =System.currentTimeMillis();
outStream =new FileOutputStream(fileName); outStream =new BufferedOutputStream(outStream);
for(int i=1000000;--i>=0;){
outStream.write(i);}
inStream =new FileInputStream(fileName); inStream =new BufferedInputStream(inStream);
while(inStream.read()!=-1) {// }
java . , , java.io.Serializable ( , , ). java.io.Serializable . , .
|
|
, , , , ( , ), , . Java - , Windows, , Unix, .
java.io ObjectInput, ObjectOutput ObjectInputStream ObjectOutputStream . OutputStream, ObjectOutputStream. writeObject() . :
Integer(1) ByteArrayOutputStream os =new ByteArrayOutputStream();
Object objSave =new Integer(1);
ObjectOutputStream oos=new ObjectOutputStream(os); oos.writeObject(objSave);
, objSave,
byte[] bArray = os.toByteArray();
, :
byte[] bArray =os.toByteArray(); // ByteArrayInputStream is =new ByteArrayInputStream(bArray); ObjectInputStream ois =new ObjectInputStream(is); Object objRead =ois.readObject();
. . , . :
, private
.
set- , .
, . . , , , . , . , , .. , , .. - .
, , , . , , , . , , , , . . , java.io.InvalidClassException.
,
( , Serializable) . . .