java学习内容回顾(string,流)

1.string类

*1.concat():主要是用于两个不同的字符串连接(与“+”的用法一样)

*2.提取和收索:

**1int indexof(int ch或string value):收索第一个出现ch或(字符串value)的索引位置;

**2int lastIndexof(int ch或string value):收索最后一个出现ch或(字符串value)的索引位置;

**3string  substring(int index):提取从索引位置开始的部分字符串;

**4string  substring(int index,int endindex):提取int index和int endindex之间的字符串;

System.out.println("欢迎进入作业提交系统");
        Scanner input =new Scanner(System.in);
        System.out.println("请输入Java文件名");
        String fileName=input.next();
        System.out.println("请输入邮箱");
        String email=input.next();
        if (fileName.indexOf(".")!=-1&&fileName.indexOf(".")!=0&&
                fileName.substring(fileName.indexOf(".")).equals(".java")){
            flag=true;    
        }else {
            System.out.println("文件名失效");
        }
        if (email.indexOf("@")!=-1&&email.indexOf(".")>email.indexOf("@")) {
            flag=true;
            
        }else {
            System.out.println("E-mail失效");
        }
        
        if (flag) {
           System.out.println("作业提交成功");
        }else {
            System.out.println("作业提交失败");
        }*/
        
        
        //string的拆分方法spilt;
        /*String word="春眠不觉晓;处处闻啼鸟;夜来风雨声;花落知多少";
        String[]words=word.split(";");//按照分号进行拆分,拆分后放入数组中
        for (int i = 0; i < words.length; i++) {
            System.out.println(words[i]);

        }*/

2.流:

*1.流:输入流:输出流;

*2.输入流:字节输入流(InputStream):字符输入流(Reader);

*3.输出流:字节输出流(OutputStream):字符输出流(Write);

例子:package com.stringlei.text;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class InputDome {
    public static void main(String[] args) {
        FileInputStream fis=null;
        
        try {
            //创建文件输入流的对象
            fis=new FileInputStream("D:/test.txt");
            System.out.println("字节数"+fis.available());
            //使用输入流的read()方法
            /*int date;
            while ((date=fis.read())!=-1){
                System.out.print((char)date);    
            }*/
            
            //使用输入流read(byte[]b)的方法
            int  str;
            byte[]b=new byte[fis.available()];
            while ((str=fis.read(b))!=-1) {
                for (int i = 0; i < str; i++) {
                    System.out.print((char)b[i]);
                }
                
            }
    
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            try {
                //关闭输入流
                fis.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

}
}




猜你喜欢

转载自blog.csdn.net/ybb520chongren_/article/details/80103956