File IO

    xiaoxiao2021-04-17  52

    package dkl; import java.io.FileInputStream; import java.io.File; import java.io.IOException; public class Day_1 { /** * @param args */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub // File file = new File("E:/2223579774.txt"); // file. createNewFile(); FileInputStream fis = new FileInputStream("E:/2223579774.txt"); byte[] b=new byte[1024]; int data =fis.read(b); while(data!=-1){ String temp=new String (b,0,data); System.out.println(temp); data=fis.read(b); } // if(file.exists()){ // System.out.println("exists"); // } // File file2=file.getAbsoluteFile(); // long length=file.length(); // long time=file.lastModified(); // System.out.println("sfnj"+length); // System.out.println(time); // System.out.println(file2); }

    }

    package bhu; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.io.FileNotFoundException; import java.io.FileReader; public class Day_2 { /** * @param args */ public static void main(String[] args)throws IOException { // TODO Auto-generated method stub // FileWriter w = new FileWriter("E:/2223579774.txt"); // String words="agskdgasjkdgahdgjh!!!!!!!!!"; // w.write(words); // w.close(); // Reader r = new FileReader("E:/2223579774.txt"); // BufferedReader br=new BufferedReader(r); // String line; // while((line=br.readLine())!=null){ // System.out.println(line); // } // br.close(); // r.close(); Writer w = new FileWriter("E:/2223579774.txt"); BufferedWriter bw=new BufferedWriter(w); String words="545654"; bw.write(words); bw.close(); w.close(); } }

    package bhu; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class asdad { /** * @param args */ public static void main(String[] args) throws IOException{ // // TODO Auto-generated method stub // InputStream i=new InputStream ("桌面/陈文杰.jpg");  // DataInputStream di=new DataInputStream(i); // OutputStream o =new OutputStream("桌面/陈文杰.jpg"); // DataInputStream ds=new DataInputStream(o); // byte[] b=new byte[1024]; // int data; // while((data=di.read(b))!=-1){ // ds.write(b,0,data); // } // ds.close(); // o.close(); // di.close(); // i.close(); // System.out.println("habdsbdjabd!!!!!!!!"); } }

    转载请注明原文地址: https://ju.6miu.com/read-674121.html

    最新回复(0)