Important Blog:
http://blog.csdn.net/hguisu/article/details/7418161
- File dir = new file ("\\root"); Directory
- File F1 = new file (dir, "FileOne.txt"); File
Dir.mkdir ();//Create Directory
F1.createnewfile ();//Create File
All classes required for streaming I/O are included in the Java.io package. There are four basic classes in the Java.io package: InputStream, OutputStream, and reader, and writer classes that handle byte streams and character streams, respectively:
Commonly used are Bufferedinputstream and Bufferedoutputstream (buffering), FileReader and FileWriter.
5. Application of FileInputStream flow and FileOutputStream
Use the program to copy the file File1.txt to File2.txt.
[Java] View plain copy print?
Import Java.io.File;
Import java.io.IOException;
Import Java.io.FileOutputStream;
Import Java.io.FileInputStream;
public class Testfile {
public static void Main (String args[]) throws IOException {
try {
File InFile = new file ("Copy.java");
File OutFile = new file ("Copy2.java");
FileInputStream FinS = new FileInputStream (inFile);
FileOutputStream Fouts = new FileOutputStream (outFile);
int C;
while ((c = Fins.read ())! =-1) {
Fouts.write (c);
}
Fins.close ();
Fouts.close ();
} catch (IOException e) {
System.err.println ("Filestreamstest:" + e);
}
}
}
3 ) keyboard input stream read to memory
Connect BufferedReader with standard data streams
InputStreamReader sin=new InputStreamReader (system.in);
BufferedReader bin=new BufferedReader (sin);
[Java] view plain copy
Print?
- import java.io.*;
- Public class Readwritetofile {
- Public Static void Main (String args[]) throws IOException {
- InputStreamReader sin = new inputstreamreader (system.in);
- BufferedReader bin = new bufferedreader (sin);
- FileWriter out = new FileWriter ("MyFile.txt");
- BufferedWriter bout = new bufferedwriter (out);
- String s;
- (s = Bin.readline ()). Length () > 0) {
- Bout.write (S, 0, s.length ());
- 12.}
- 13.
- 14.}
15.}
Program Description:
Read the characters from the keyboard and write to the method of the BufferedReader class in the file: String readLine ()
Function: Reads a line of string, ending with a carriage return.
Methods of the BufferedWriter class: Bout.write (Strings,offset,len)
Function: Writes the string s from offset to the Len length string from the buffer to somewhere.
Java input/output stream memo