FileDialog- Save FileDialog fileBox new FileDialog( mainWindow,Save As", FileDialog. SAVE fileBox setvisible( true )i Save As 区 ave In Ch11 团圈回 自 Address Booki 目 TestFileOutputStream ADdress Storage BTestPrintStream 目 TestBufferedReader ETestD 百 TestDataDutput Stream 口 TestFilelnputStream Save as type: All Files(:") Cancel C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 11-6
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 11 - 6 FileDialog - Save FileDialog fileBox = new FileDialog( mainWindow, “Save As”, FileDialog.SAVE ); fileBox.setVisible( true );
LOW-Level File I/0-output //set up file and stream File outFile new File("samplel data")i Fileoutputstream outstream new Fileoutputstream( outFile //data to save byte[] byteArray =110, 20, 30,40 50,60,70,80} //write data to the stream outstream write( byteArray )i //output done, so close the stream outstream close()i C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 11-7
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 11 - 7 Low-Level File I/O – Output //set up file and stream File outFile = new File("sample1.data"); FileOutputStream outStream = new FileOutputStream( outFile ); //data to save byte[] byteArray = {10, 20, 30, 40, 50, 60, 70, 80}; //write data to the stream outStream.write( byteArray ); //output done, so close the stream outStream.close();
LOW-Level File I/0-Input //set up file and stream File inFile new File("samplel data) FileInputstream inStream new FileInputstream(inFile)i //set up an array to read data in int filesize (int)inFile. length(i byte[] byteArray new byte[filesize] //read data in and display them instream read(byteArray) for (int i =0; i< filesize; i++)i outputBox. printLine (byteArray [il)i //input done, so close the stream inStream close() C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 11-8
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 11 - 8 Low-Level File I/O – Input //set up file and stream File inFile = new File("sample1.data"); FileInputStream inStream = new FileInputStream(inFile); //set up an array to read data in int fileSize = (int)inFile.length(); byte[] byteArray = new byte[fileSize]; //read data in and display them inStream.read(byteArray); for (int i = 0; i < fileSize; i++) { outputBox.printLine(byteArray[i]); } //input done, so close the stream inStream.close();