1、Print流的使用
package cn.kongxh.io7;
import java.io.* ;
public class PrintDemo01{
public static void main(String arg[]) throws Exception{
PrintStream ps = null ; // 声明打印流对象
// 如果现在是使用FileOuputStream实例化,意味着所有的输出是向文件之中
ps = new PrintStream(new FileOutputStream(new File("d:" + File.separator + "test.txt"))) ;
ps.print("hello ") ;
ps.println("world!!!") ;
ps.print("1 + 1 = " + 2) ;
ps.close() ;
}
};
2、
1 package cn.kongxh.io7;
2
3 import java.io.* ;
4 public class PrintDemo02{
5 public static void main(String arg[]) throws Exception{
6 PrintStream ps = null ; // 声明打印流对象
7 // 如果现在是使用FileOuputStream实例化,意味着所有的输出是向文件之中
8 ps = new PrintStream(new FileOutputStream(new File("d:" + File.separator + "test.txt"))) ;
9 String name = "李兴华" ; // 定义字符串
10 int age = 30 ; // 定义整数
11 float score = 990.356f ; // 定义小数
12 char sex = 'M' ; // 定义字符
13 ps.printf("姓名:%s;年龄:%d;成绩:%f;性别:%c",name,age,score,sex) ;
14 ps.close() ;
15 }
16 };
3、
1 package cn.kongxh.io7;
2
3 import java.io.* ;
4 public class PrintDemo03{
5 public static void main(String arg[]) throws Exception{
6 PrintStream ps = null ; // 声明打印流对象
7 // 如果现在是使用FileOuputStream实例化,意味着所有的输出是向文件之中
8 ps = new PrintStream(new FileOutputStream(new File("d:" + File.separator + "test.txt"))) ;
9 String name = "李兴华" ; // 定义字符串
10 int age = 30 ; // 定义整数
11 float score = 990.356f ; // 定义小数
12 char sex = 'M' ; // 定义字符
13 ps.printf("姓名:%s;年龄:%s;成绩:%s;性别:%s",name,age,score,sex) ;
14 ps.close() ;
15 }
16 };