public class BufferWriterText01 {
public static void main(String[] args) {
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream("D:\\Text\\java01.text",true);
OutputStreamWriter outputStream = new OutputStreamWriter(fileOutputStream);
BufferedWriter bufferedWriter = new BufferedWriter(outputStream);
bufferedWriter.write("HEllo,world\n");
bufferedWriter.write("Number N0.1\n");
bufferedWriter.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
public class FileInoutStreamText02 {
public static void main(String[] args) {
FileInputStream fis = null;
try {
fis = new FileInputStream("D:\\Text\\联系.txt");
int reaData = 0;
while ((reaData = fis.read()) != -1){
System.out.println(reaData);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
public class FileOutputStreamText01 {
public static void main(String[] args) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream("D:\\Text\\联系.txt",true);
String s = "我爱你,但是我现在需要变得更好!!!";
byte[] byt = s.getBytes();
fos.write(byt);
fos.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
public class FileReaderText01 {
public static void main(String[] args) {
FileReader fir = null;
try {
fir = new FileReader("D:\\Text\\联系.txt");
int ReadCount = 0;
char[] chars = new char[4];
while((ReadCount = fir.read(chars)) != -1){
System.out.print(new String(chars,0,ReadCount));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fir != null) {
try {
fir.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}