zoukankan      html  css  js  c++  java
  • 第十周总结

    课程总结

    1.File类

    如果要使用File类,则要使用File类的构造方法,且实例化File类的时候,必须要给出设置好的路径。

    public File (String pathname)

    File类中的主要方法和常量:

    File类中的两个常量
    pathSeparator:表示;
    separator:表示 ###2.RandomAccessFile类
    常用的操作方法:

    3.字节流与字符流基本操作:

    程序需要数据的时候要使用输入流读取数据,而当程序需要将一些数据保存起来的时候,就要使用输出流完成。

    在Java中IO操作流程:
    (1)使用File类打开一个文件。
    (2)通过字节流或字符流的子类指定输出的位置。
    (3)进行读/写操作。
    (4)关闭输入/输出。

    4.字节流:

    字节输出流OutputStream类的定义:

    public abstract class OutputStream
    extends Object
    implements Closeable,Flushable

    OutputStream类的常用方法:

    字节输入流InputStream类的定义:

    public abstract class IntputStream
    extends Object
    implements Closeable

    InputStream类的常用方法:

    5.字符流:

    字符输出流Writre类的定义:

    public abstract class Writre
    extends Object
    implements Appendable,Closeable,Flushable

    Writre类的常用方法:

    把奇数位 的小写字母改为大写

    复制代码
    package 字符流;
    
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    
    public class Test{
        public static void main(String[]args)throws Exception{
            File f=new File("f:"+File.separator+"test.txt");
            OutputStream out=null;
            out =new FileOutputStream(f);
            String str="helloworld";
            byte a[]=str.getBytes();
            for(int i=0;i<a.length;i++) {
                if(i%2==0&&a[i]>='a'&&a[i]<='z') {
                    a[i]=(byte)(a[i]-32);
                }
            }
            out.write(a);
            out.close();
        }
    }
    复制代码

    运行截图

    自我总结:

  • 相关阅读:
    Linux防火墙管理(iptables)以及开放端口配置
    CSS 样式引入方式、常用选择器以及优先级权重的计算
    初识外边距合并-margin collapsing
    纯CSS实现自适应正方形
    常用正则
    vue 学习记录
    VScode 之快速创建vue模板
    vscode之常用插件
    工具函数
    Axios之配置参数
  • 原文地址:https://www.cnblogs.com/songjiah/p/11788206.html
Copyright © 2011-2022 走看看