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

    题目:使用Java IO 将奇数位小写改为大写
    实验代码:

    package Java;
    
    import java.io.File;
    import java.io.FileOutputStream;
    
    public class 大写 {
    	public static void main(String[] args) throws Exception{                         
            File f=new File("d:"+File.separator+"test.txt");             
            FileOutputStream out=null;                      
            out=new FileOutputStream(f);           
            String str="helloTomorrow";                           
            byte b[]=str.getBytes();                       
            for(int i=0;i<b.length;i++) {
                if(i%2==0) {            
                    out.write((byte) (b[i]-32)); 
                }
                else {
                    out.write(b[i]);
                }
            }
            out.close();
        }
    
    }
    
    

    运行结果截图:

    学到了什么:

    字节流与字符流的基本操作
    字节输出流:OutputStream

    public abstruct class OutputStream
    extends Object
    implments Closeable,Flushable
    

    向文件中写入字符串

    package Java;
    
    import java.io.File;
    import java.io.FileOutputStream;
    public class OutputStream {
    	public static void main(String[] args) throws Exception{
    		File f = new File("d:"+File.separator+"test.txt");
    		FileOutputStream out = null;
    		out = new FileOutputStream(f);
    		String str = "Hello World";
    		byte b[] = str.getBytes();
    		out.write(b);
    		out.close();
    		}
    }
    


    字节输入流:InputStream

    public abstract class InputStream
    extends Object
    implements Clossable
    

    从文件中读取内容:

    package Java;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    
    public class JavaIO {
    	public static void main(String[] args)throws Exception{
    		
    		File f = new File("d:"+File.separator+"test.txt");
    		InputStream input=null;
    		input = new FileInputStream(f);
    		byte b[]=new byte[1024];
    		input.read(b);
    		input.close();
    		System.out.println("内容为:"+new String(b));
    	}
    }
    
    

    字符输出流:Writer

    public abstract class Write
    extends Object
    implements Appendable,Closeable,Flushable
    
    FileWrite 类的构造方法定义:
    public FileWrite(File file) throws IOException
    

    字符输入流:Reader
    定义:

    public abstract class Reader
    extends Object
    implements Readable,Closeable
    

    学习不足及改进

    1.不能写出程序流程图,
    2.无法保证程序的完备性(每次写完一个程序都需要修改)
    3.还需照着书本写出相应代码,有些类的常用方法不太清楚

  • 相关阅读:
    About Inside the Azure Storage Outage of November 18th
    Microsoft Azure 的一些限制 Global
    js递归遍历树形json数据,根据关键字查找节点
    如何修改 WordPress 的默认 Gravatar 头像
    flatpickr功能强大的日期时间选择器插件
    express框架,使用 static 访问 public 内静态文件
    nodejs实时的检测系统文件的变化(无需重启服务)
    redis的常用命令
    NPM install -save 和 -save-dev 傻傻分不清
    Git的使用--如何将本地项目上传到Github
  • 原文地址:https://www.cnblogs.com/ImportantMagic/p/11784672.html
Copyright © 2011-2022 走看看