Code pasted. I have already tried it and can compile it normally.
Package Org. mark. streamrw; import Java. io. file; import Java. io. fileoutputstream; import Java. io. outputstream;/*** byte stream output outputstream * Note: 1. Write (byte [] B) array writing; ** @ author Mark */public class outputstream1 {/*** @ Param ARGs */public static void main (string [] ARGs) throws exception {// todo auto-generated method stub // Step 1: use the File class to find a file = new file ("D:" + file. separator + "test.txt"); // Step 4: Use the subclass Instantiate the parent class Object outputstream output = NULL; Output = new fileoutputstream (File); // instantiate the object through object polymorphism. // Step 2: write string STR = "Hello world !!! "; Byte [] B = Str. getbytes (); // convert to byte array output. write (B); // view the API write (byte [] B) // Step 4: Disable the output stream output. close (); // do not forget to close it. // if the file does not exist, the user will take the initiative to create the file ;}}
Write (int B) the specified byte to this output stream.
Package Org. mark. streamrw; import Java. io. file; import Java. io. fileoutputstream; import Java. io. outputstream; // Use Write (int B) to write specified bytes to this output stream. Public class outputstream2 {/*** @ Param ARGs */public static void main (string [] ARGs) throws exception {// todo auto-generated method stub // Step 3: use the file class to find a file = new file ("D:" + file. separator + "test.txt"); // Step 4: instantiate the parent class Object outputstream output = NULL through subclass; Output = new fileoutputstream (File); // perform object polymorphism, instantiation // Step 2: Write string STR = "Hello world !!! "; Byte [] B = Str. getbytes (); // convert it to a byte array // output. write (B); // view API write (byte [] B) for (INT I = 0; I <B. length; I ++) {output. write (B [I]); // write (int B) writes the specified byte to this output stream. } // Step 2: Close the output stream output. close (); // do not forget to close it. // if the file does not exist, the user will take the initiative to create the file; // The file content does not exist }}
// Append the file, line feed,
String STR = "\ r \ nhello world !!! "; // \ R \ n line feed
If you have any questions, leave me a message.
Basic file operations-outputstream byte output stream