Java I/O read-write

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.