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

    本周实验课,课堂作业
    因为求助了同学,所以回来又做了一遍

    课堂练习Java IO
    题目需求:完成文件复制操作
    D:test目录下有一个文件demo1.txt。请将d: estdemo1.txt文件内容复制到一个新的文件d: estdemo2.txt,并将其中所左右的小写字母换成大写字母。

    1、实验代码

    package demo;
    
    import java.io.*;
    import java.io.IOException;
    
    public class demo1 {
    
    	public static void main(String[] args) {
    		byte byt[] ="This is a project Java IO".getBytes();
    		String path="d:"+File.separator+"text"+File.separator+"demo1.txt";
    		String path1="d:"+File.separator+"text"+File.separator+"demo2.txt";
    		File file=new File(path);
    		try {
    			FileOutputStream out = new FileOutputStream(path);
    			out.write(byt);
    			out.close();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		try{
    			FileInputStream in = new FileInputStream(path);
    			byte bye[] = new byte[1024];
    			int len = in.read(bye);
    			
    		}catch(Exception e){
    			e.printStackTrace();
    		}
    		
    		File f=new File(path1);
    		try{
    			FileOutputStream fos = new FileOutputStream(path1);
    			String str = new String(byt);
    			String string = str.toUpperCase();
    			byte bee[] = string.getBytes();
    			fos.write(bee);
    			fos.close();
    		}catch(Exception e){
    			e.printStackTrace();
    		}
    		
    		
    	}
    }
    

    2、实验结果

    本周学习总结
    本周主要学习了字节流与字符流。
    字节流
    字节流主要是操作byte类型数据,以byte数组为准,主要操作类就是OutputStream类和InputStream类。

    字符流
    在程序中一个字符等于两个字节,java提供了reader和writer两个专门操作字符流的类。

  • 相关阅读:
    查看java代码,命令,ctrl+r
    JVM调优
    springboot线程池
    jpa
    复制java对象,jpa,save
    springboot添加切面
    gunicorn 实现 gevent 多线程
    经典算法
    python-生僻字转拼音
    HTML介绍
  • 原文地址:https://www.cnblogs.com/gaotian250yj912/p/11773345.html
Copyright © 2011-2022 走看看