【每日日报】第三十四天---Scanner类的应用
1 今天继续看书
Scanner类的应用
1 package File;
2 import java.util.Scanner;
3
4 public class ScannerDemo {
5 public static void main(String[] args){
6 Scanner con=new Scanner(System.in);
7 String line=con.nextLine();
8 int i=con.nextInt();
9 double d=con.nextDouble();
10 System.out.println(line);
11 System.out.println(i);
12 System.out.println(d);
13 con.close();
14 }
15 }
对象序列化
1 package File;
2 import java.io.Serializable;
3 public class Person implements Serializable{
4 private String name;
5 private int age;
6 public String getName(){
7 return name;
8 }
9 public void setName(String name){
10 this.name=name;
11 }
12 public int getAge(){
13 return age;
14 }
15 public void setAge(int age){
16 this.age=age;
17 }
18 public String toString(){
19 return "姓名:"+name+",年龄:"+age;
20 }
21 }
使用ObjectOutputStream将对象写到文件中
1 package File;
2 import java.io.FileOutputStream;
3 import java.io.IOException;
4 import java.io.ObjectOutputStream;
5
6 public class ObjectOutputstreamDemo {
7 public static void main(String[] args)throws IOException{
8 ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("D:/Hello.txt"));
9 Person p=new Person();
10 p.setAge(20);
11 p.setName("吴征云");
12 oos.writeObject(p);
13 oos.close();
14 }
15 }
对象反序列化
1 package File;
2 import java.io.FileInputStream;
3 import java.io.IOException;
4 import java.io.ObjectInputStream;
5
6 public class ObjectInputStreamDemo {
7 public static void main(String[] args)throws IOException,ClassNotFoundException{
8 ObjectInputStream ois=new ObjectInputStream(new FileInputStream("D:/Hello.txt"));
9 Person p=(Person)ois.readObject();
10 ois.close();
11 System.out.println(p);
12 }
13 }
序列化一组对象
1 package File;
2 import java.io.FileOutputStream;
3 import java.io.IOException;
4 import java.io.ObjectOutputStream;
5
6 public class ObjectInputStreamDemo2 {
7 public static void main(String[] args)throws IOException{
8 ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("D:/Hello.txt"));
9 Person p=new Person();
10 p.setAge(20);
11 p.setName("吴征云");
12 Person p2=new Person();
13 p.setAge(20);
14 p.setName("吴征云22");
15 Person[] ps={p,p2};
16 oos.writeObject(ps);
17 oos.close();
18 }
19 }
2 没什么问题
3 明天继续看书
【每日日报】第三十四天---Scanner类的应用的更多相关文章
- COJ966 WZJ的数据结构(负三十四)
WZJ的数据结构(负三十四) 难度级别:C: 运行时间限制:20000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 给一棵n个节点的树,请对于形如"u ...
- NeHe OpenGL教程 第三十四课:地形
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- JAVA之旅(三十四)——自定义服务端,URLConnection,正则表达式特点,匹配,切割,替换,获取,网页爬虫
JAVA之旅(三十四)--自定义服务端,URLConnection,正则表达式特点,匹配,切割,替换,获取,网页爬虫 我们接着来说网络编程,TCP 一.自定义服务端 我们直接写一个服务端,让本机去连接 ...
- Java进阶(三十四)Integer与int的种种比较你知道多少?
Java进阶(三十四)Integer与int的种种比较你知道多少? 前言 如果面试官问Integer与int的区别:估计大多数人只会说到两点:Ingeter是int的包装类,注意是一个类:int的初值 ...
- Gradle 1.12用户指南翻译——第三十四章. JaCoCo 插件
本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...
- SQL注入之Sqli-labs系列第三十四关(基于宽字符逃逸POST注入)和三十五关
开始挑战第三十四关和第三十五关(Bypass add addslashes) 0x1查看源码 本关是post型的注入漏洞,同样的也是将post过来的内容进行了 ' \ 的处理. if(isset($_ ...
- spring boot 常见三十四问
Spring Boot 是微服务中最好的 Java 框架. 我们建议你能够成为一名 Spring Boot 的专家. 问题一 Spring Boot.Spring MVC 和 Spring 有什么区别 ...
- “全栈2019”Java多线程第三十四章:超时自动唤醒被等待的线程
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...
- 第三百三十四节,web爬虫讲解2—Scrapy框架爬虫—Scrapy爬取百度新闻,爬取Ajax动态生成的信息
第三百三十四节,web爬虫讲解2—Scrapy框架爬虫—Scrapy爬取百度新闻,爬取Ajax动态生成的信息 crapy爬取百度新闻,爬取Ajax动态生成的信息,抓取百度新闻首页的新闻rul地址 有多 ...
随机推荐
- sql 名词解析
针对这个 sql 语句进行解析 1 SELECT 2 a.* 3 , b.L12_create_time L1第一次转L2的时间 4 , ROUND(c.L1_pending/60, 2) " ...
- Elasticsearch-CentOS7单机安装测试
排版比较丑,但按照此步骤执行一定会搭建成功. 一.环境描述及准备 1.下载Elasticsearch包 curl -L -O https://artifacts.elastic.co/download ...
- laravel7 数据库数据导出至 xlsx
网址参考: https://learnku.com/articles/32391 1:安装excel插件 安装方式 composer require maatwebsite/excel 2:excel ...
- Owin + WebApi + OAuth2 搭建授权模式(授权码模式 Part I)
绪 最近想要整理自己代码封装成库,也十分想把自己的设计思路贴出来让大家指正,奈何时间真的不随人意. 想要使用 OWIN 做中间件服务,该服务中包含 管线.授权 两部分.于是决定使用 webapi .O ...
- 11 Java的方法 递归
6.递归 A方法调用B方法,我们很容易理解! 递归就是:A方法调用A方法!就是自己调用自己 利用递归可以用简单的程序来解决一些复杂的问题. 它通常把一个大型复杂的问题层层转化为一个与原问题相似的规模较 ...
- LGP5204题解
@CF1327F 最小值看着有点怪,先转化成最大值吧...反正没啥区别... 考虑把最大值相同的区间和限制为这个最大值的区间都拿出来.然后离散化.问题变为让所有区间都满足最值为 \(c\). 考虑 D ...
- python实现解析markdown文档中的图片,并且保存到本地~
背景 前阵子简书好像说是凉了,搞得我有点小慌,毕竟我的大部分博客都是放在简书上面的,虽然简书提供了打包导出功能,但是只能导出文字,图片的话还是存在简书服务器上面,再加上我一直想要重新做一个个人博客,于 ...
- PO模式在selenium自动化测试框架有什么好处
PO模式是在UI自动化测试过程当中使用非常频繁的一种设计模式,使用这种模式后,可以有效的提升代码的复用能力,并且让自动化测试代码维护起来更加方便. PO模式的全称叫page object model( ...
- python3判断一个数是否为素数
while True: num = int(input('请输入一个数:')) for i in range(2,num):#判断在num之前的数能不能把num整除 if(num%i == 0): p ...
- python+pytest接口自动化(10)-session会话保持
在接口测试的过程中,经常会遇到有些接口需要在登录的状态下才能请求,否则会提示请登录,那么怎样解决呢? 上一篇文章我们介绍了Cookie绕过登录,其实这就是保持登录状态的方法之一. 另外一种方式则是通过 ...