易截截图软件、单文件、免安装、纯绿色、仅160KB

java 文件读写_FileReader

package test;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Test {
 public static void main(String arg[]) {
  String fileName = "E:\\share\\test.txt";
  String writeData = "HelloWorld!\r\nnihao我的内存是3G的 ";
  File file = new File(fileName);
  if(file.exists()){
   file.delete();
  }
  
  char[] byteOutData = writeData.toCharArray();
  char[] byteInData = new char[50];
  int length = 0;
  
  try {
   file.createNewFile();
   if(file.exists() && file.canWrite()){
    FileWriter fileWrite = new FileWriter(file);
    fileWrite.write(byteOutData);
    fileWrite.close();
   }
   if (file.exists() && file.canRead()) {
    FileReader fileReader = new FileReader(file);
    while((length = fileReader.read(byteInData)) !=-1){
     System.out.print(new String(byteInData,0,length));
    }
     fileReader.close();
   }
  } catch (IOException e) {
   System.out.println("IOException occur");
   e.getMessage();
  }
 }
}


相关文档:

sql 2005 存储过程分页 java 代码

 create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',         
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列 ......

Java NIO API详解

 
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......

Java 过滤字符串(用模式匹配实现)

//Number 11   过滤字符串中的非数字字符
import java.util.regex.*;
import java.util.Scanner;
public class GuoLv{
    public static void main(String args[]){
       Scanner    reader    = new Scanner(System.in);
  ......

Java相对路径/绝对路径总结(转)

1.基本概念的理解
绝对路径:绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,(URL和物理路径)例如:
C:xyz est.txt 代表了test.txt文件的绝对路径。http://www.sun.com/index.htm也代表了一个URL绝对路径。
相对路径:相对与某个基准目录的路径。包含Web的相对路径(HTML中的相对目录),例如:在
Servlet ......

Java读取配置文件

import java.util.Properties;
public class ConfigReader {
private static Properties cache = new Properties();
static{
   try {
    cache.load(ConfigReader .class.getClassLoader().getResourceAsStream("config.properties"));
   } catch (Exception e) {
 &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号