WEB开发网
开发学院WEB开发Jsp java 文件读写_FileInputStream_File 阅读

java 文件读写_FileInputStream_File

 2009-12-30 21:14:43 来源:WEB开发网   
核心提示:package test;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;public class Test { public static voi
package test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test {

public static void main(String arg[]) {
 String fileName = "E:\\share\\test.txt";
 File file = new File(fileName);
 String writeData = "HelloWorld!\r\nnihao我的内存是2G的 ";
 byte[] byteOutData = writeData.getBytes();
 byte[] byteInData = new byte[20];
 int length = 0;
 if (file.isFile()) {
  file.delete();
 }
 try {

  if (file.createNewFile() && file.canWrite()) {
  FileOutputStream fileOutStream = new FileOutputStream(file);
  fileOutStream.write(byteOutData);
  fileOutStream.close();
  }
  if (file.canRead()) {
  FileInputStream fileInStream = new FileInputStream(file);
  while ((length = fileInStream.read(byteInData)) != -1) {
   System.out.PRint(new String(byteInData, 0, lenght));
  }
  fileInStream.close();
  }
 } catch (IOException e) {
  System.out.println("IOException occur");
  e.getMessage();
 }
}
}



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/whb3118/archive/2009/12/29/5099577.aspx

Tags:java 文件 读写

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接