*****1.**********************************************************************
[code]
package Testioprint;
import java.io.* ;
public class Test1 {
public static void main(String[] args) {
PrintStream ps = null ;
try {
FileOutputStream fos = new FileOutputStream("d:\\java\\test7.txt") ;
ps = new PrintStream(fos) ;
} catch(FileNotFoundException e) {
e.printStackTrace();
}
if(ps != null) {
System.setOut(ps) ;
}
int i=0 ;
for(char c=0; c<= 60000; c++) {
System.out.print(c +" ") ;
if(i ++>= 100) {
System.out.println() ; //换行
i = 0 ; //将i复原
}
}
}
}
[/code]
*******2**************************************************************
[code]
package Testioprint;
import java.io.* ;
public class test2 {
public static void main(String[] args) {
String filename = args[0] ; //命令行参数
if(filename != null) {
list(filename, System.out) ;
}
}
public static void list(String f, PrintStream fs) {
try {
BufferedReader br = new BufferedReader(new FileReader(f)) ;
String s = null ;
while((s=br.readLine())!= null) {
fs.println(s) ;
}
br.close() ;
} catch (IOException e) {
fs.println("read file error") ;
}
}
}
[/code]
*****3*******************************************************************
[code]
package Testioprint;
import java.io.*;
import java.util.* ;
public class test3 {
public static void main(String []args) {
int year,month,day ;
year = Calendar.getInstance().get(Calendar.YEAR) ;
month = Calendar.getInstance().get(Calendar.MONTH) ;
day = Calendar.getInstance().get(Calendar.DATE) ;
String s = null ;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;
try {
PrintWriter pw = new PrintWriter(new FileWriter("d:/java/tests.txt",true)) ;
while ((s=br.readLine()) != null) {
if(s.equalsIgnoreCase("exit"))
break ;
System.out.println(s.toUpperCase()) ; //输出转成大写的字符
pw.println(s.toUpperCase()) ; //打印 String s
pw.println("------------") ;
pw.flush();
}
pw.println("==新添加日期是:"+ year+"年-"+ month +"-月-"+ day +"-日"+ "==" ) ;
pw.println() ;
pw.flush();
pw.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
[/code]
[code]
package Testioprint;
import java.io.* ;
public class Test1 {
public static void main(String[] args) {
PrintStream ps = null ;
try {
FileOutputStream fos = new FileOutputStream("d:\\java\\test7.txt") ;
ps = new PrintStream(fos) ;
} catch(FileNotFoundException e) {
e.printStackTrace();
}
if(ps != null) {
System.setOut(ps) ;
}
int i=0 ;
for(char c=0; c<= 60000; c++) {
System.out.print(c +" ") ;
if(i ++>= 100) {
System.out.println() ; //换行
i = 0 ; //将i复原
}
}
}
}
[/code]
*******2**************************************************************
[code]
package Testioprint;
import java.io.* ;
public class test2 {
public static void main(String[] args) {
String filename = args[0] ; //命令行参数
if(filename != null) {
list(filename, System.out) ;
}
}
public static void list(String f, PrintStream fs) {
try {
BufferedReader br = new BufferedReader(new FileReader(f)) ;
String s = null ;
while((s=br.readLine())!= null) {
fs.println(s) ;
}
br.close() ;
} catch (IOException e) {
fs.println("read file error") ;
}
}
}
[/code]
*****3*******************************************************************
[code]
package Testioprint;
import java.io.*;
import java.util.* ;
public class test3 {
public static void main(String []args) {
int year,month,day ;
year = Calendar.getInstance().get(Calendar.YEAR) ;
month = Calendar.getInstance().get(Calendar.MONTH) ;
day = Calendar.getInstance().get(Calendar.DATE) ;
String s = null ;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;
try {
PrintWriter pw = new PrintWriter(new FileWriter("d:/java/tests.txt",true)) ;
while ((s=br.readLine()) != null) {
if(s.equalsIgnoreCase("exit"))
break ;
System.out.println(s.toUpperCase()) ; //输出转成大写的字符
pw.println(s.toUpperCase()) ; //打印 String s
pw.println("------------") ;
pw.flush();
}
pw.println("==新添加日期是:"+ year+"年-"+ month +"-月-"+ day +"-日"+ "==" ) ;
pw.println() ;
pw.flush();
pw.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
[/code]