zoukankan      html  css  js  c++  java
  • java练习题在一个文件里面输入内容在另一个文件里面可以查看

    package shurushuchu;
    import java.io.*;
    public class test5 {
        public static void main(String[] args) {
            try {
            File file = new File("d:/IoDemo.java");
            if(!file.exists())
            {
                        file.createNewFile();
            }
            //输出的内容
            FileOutputStream fos = new FileOutputStream(file);
            String str ="你好我是张三";
            //把数据源转成byte[]数组
            byte [] b = str.getBytes();
            //写入数据
            fos.write(b);
            //关闭流自动释放文件
            fos.close();
            System.out.println("写入文件完成");
            //字节输入流
            FileInputStream fis = new FileInputStream(file);
            
            //装载读入的数组
            byte [] d = new byte[12];
            //全部内容的字符串
            int i = fis.read(d);
            String str1 = new String(d);
            System.out.println("读入的内容"+str1);
            //关闭文件
            fis.close();
            //创建新文件
                File file1 = new File("d:/iodemo.txt,");
                if(!file1.exists())
                {
                            file1.createNewFile();
                }
                FileWriter sos = new FileWriter(file1);
                sos.write(str1);
                sos.close();
                
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            
                    
        }
        }
  • 相关阅读:
    自定义Dialog
    AlertDialog
    Toast
    WebView
    《构建之法》阅读笔记3
    UI组件之GridView
    ScrollView&HorizontalScrollView
    UI组件之ImageView
    UI组件之ListView
    每周总结(1.24)
  • 原文地址:https://www.cnblogs.com/zzyu/p/5548903.html
Copyright © 2011-2022 走看看