您现在的位置是:主页 > news > 网站优化公司排行/如何网络营销

网站优化公司排行/如何网络营销

admin2025/6/29 3:52:32news

简介网站优化公司排行,如何网络营销,成成品网站源码有限公司,房地产客户管理系统有哪些1.标准输入输出流 2.打印流 3.数据流 文章目录1.标准输入输出流2.打印流2.1 打印流_格式化输出3.数据流1.标准输入输出流 public class demo06 {public static void main(String[] args) {BufferedReader br null;try {InputStreamReader isr new InputStreamReader(System.…

网站优化公司排行,如何网络营销,成成品网站源码有限公司,房地产客户管理系统有哪些1.标准输入输出流 2.打印流 3.数据流 文章目录1.标准输入输出流2.打印流2.1 打印流_格式化输出3.数据流1.标准输入输出流 public class demo06 {public static void main(String[] args) {BufferedReader br null;try {InputStreamReader isr new InputStreamReader(System.…

1.标准输入输出流
2.打印流
3.数据流

文章目录

        • 1.标准输入输出流
        • 2.打印流
          • 2.1 打印流_格式化输出
        • 3.数据流

1.标准输入输出流

public class demo06 {public static void main(String[] args) {BufferedReader br = null;try {InputStreamReader isr = new InputStreamReader(System.in);br = new BufferedReader(isr);while (true){String data = br.readLine();if("e".equalsIgnoreCase(data) || "exit".equalsIgnoreCase(data)){System.out.println("结束");break;}String s = data.toUpperCase();System.out.println(s);}} catch (IOException e) {e.printStackTrace();} finally {if(br !=null){try {br.close();} catch (IOException e) {e.printStackTrace();}}}}
}

在这里插入图片描述
标准输入输出流:
1.可以用scanner
2.可以用System.in方法
System.in - 转换流 - BufferedReader的ReadLine

2.打印流

打印流只可以输出没有输入
在这里插入图片描述

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 类集;
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"))) ;String name = "李兴华" ;    // 定义字符串int age = 30 ;                // 定义整数float score = 990.356f ;    // 定义小数char sex = 'M' ;            // 定义字符ps.printf("姓名:%s;年龄:%d;成绩:%f;性别:%c",name,age,score,sex) ;ps.close() ;}
};

在这里插入图片描述
可以全部都是%s也可以

import java.io.* ;
public class PrintDemo03{public static void main(String arg[]) throws Exception{PrintStream ps = null ;        // 声明打印流对象// 如果现在是使用FileOuputStream实例化,意味着所有的输出是向文件之中ps = new PrintStream(new FileOutputStream(new File("d:" + File.separator + "test.txt"))) ;String name = "李兴华" ;    // 定义字符串int age = 30 ;                // 定义整数float score = 990.356f ;    // 定义小数char sex = 'M' ;            // 定义字符ps.printf("姓名:%s;年龄:%s;成绩:%s;性别:%s",name,age,score,sex) ;ps.close() ;}
};

3.数据流

import java.io.*;public class demo08 {@Testpublic void test1() throws IOException {//打印流 输出保存在一个文件中//数据流DataOutputStream dos = new DataOutputStream(new FileOutputStream("11.txt"));dos.writeUTF("你");dos.flush();dos.writeInt(12);dos.flush();dos.writeBoolean(true);dos.flush();dos.close();}@Test//读的顺序和写的顺序一致public void test2() throws IOException {DataInputStream dis = new DataInputStream(new FileInputStream("11.txt"));String name = dis.readUTF();int i1 = dis.readInt();boolean b1 = dis.readBoolean();System.out.println(name);System.out.println(i1);System.out.println(b1);dis.close();}
}

注意数据流的话输入和输出的顺序必须一致,不然会报异常