import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
public class CopytoFile {
public static void main(String[] args) throws IOException {
// copy();将键盘录入的数据存储到文件中
// print();将键盘录入打印到控制台
// copyCo();将文件的数据打印到控制台 printCo
// method();按照UTF-8字符集来写文件
//method2();//读取按照UTF-8字符集写的文件
Properties pro=System.getProperties();
pro.list(new PrintStream("sysinfo.txt"));
}
private static void method2() throws UnsupportedEncodingException,
FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream("halei.txt"), "UTF-8"));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
System.out));
String line = null;
while ((line = br.readLine()) != null) {
if (line.equals("quit"))
break;
bw.write(line.toUpperCase());
bw.newLine();
}
bw.close();
}
private static void method() throws UnsupportedEncodingException,
FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("halei.txt"), "UTF-8"));
String line = null;
while ((line = br.readLine()) != null) {
if (line.equals("quit"))
break;
bw.write(line.toUpperCase());
bw.newLine();
}
bw.close();
}
private static void copyCo() throws FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream("halei.txt")));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
System.out));
String line = null;
while ((line = br.readLine()) != null) {
if (line.equals("quit"))
break;
bw.write(line.toUpperCase());
bw.newLine();
}
bw.close();
}
private static void print() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
System.out));
String line = null;
while ((line = br.readLine()) != null) {
if (line.equals("quit"))
break;
bw.write(line.toUpperCase());
bw.newLine();
}
bw.close();
}
private static void copy() throws FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("halei.txt")));
String line = null;
while ((line = br.readLine()) != null) {
if (line.equals("quit"))
break;
bw.write(line.toUpperCase());
bw.newLine();
}
bw.close();
}
}
|
|