Package ioput;
Import Java.io.BufferedReader;
Import Java.io.BufferedWriter;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileWriter;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
public Class AAA {
/*public static void Main (string[] args) {
args = new string[]{"A", "B", "C"};
for (int i = 0; i < args.length; i++) {
System.out.println ("args[" + i + "is <" + Args[i] + ">");
}
}*/
/*public static void Main (String args[]) {
int b;
try {
System.out.println ("Please Input:");
while ((b = System.in.read ())! =-1) {
System.out.print ((char) b);
}
} catch (IOException e) {
System.out.println (E.tostring ());
}
} */
/* public static void Main (String args[]) {
String s;
Create a buffer reader to read data line-wise from the keyboard
InputStreamReader ir = new InputStreamReader (system.in);
BufferedReader in = new BufferedReader (IR);
System.out.println ("Unix system: Ctrl-d or Ctrl-c exit"
+ "\nwindows system: Ctrl-z exit");
try {
Read a row of data and standard output to the display
s = In.readline ();
ReadLine () The IOException exception is thrown if an I/O error occurs while the method is running
while (s! = null) {
System.out.println ("Read:" + s);
s = In.readline ();
}
Close the buffer reader
In.close ();
} catch (IOException e) {//catch any IO exceptions.
E.printstacktrace ();
}
}*/
Read data from disk
/*public static void Main (string[] args) {
try {
File File = new file ("D:/aaa/gbk.txt");
InputStream FileStream = new FileInputStream (file);
InputStreamReader read = new InputStreamReader (FileStream, "utf-8");
BufferedReader BufferedReader = new BufferedReader (read);
String text = null;
while ((Text =bufferedreader.readline ())!=null) {
System.out.println (text);
}
Read.close ();
} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}*/
Data written to disk
public static void Main (string[] args) {
String Path = "D:/tr/rt";
File F = new file (path);
if (!f.exists ()) {
F.mkdirs ();
}
String filename= "Test.txt";
File File = new file (f,filename);
if (!file.exists ()) {
try {
File.createnewfile ();
} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
String s = "1234567890";
try {
BufferedWriter writer = new BufferedWriter (new FileWriter (file));
Writer.write (s);
Writer.close ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}
Java I/O read-write