import java.io.*;public class abc{
  public static void main( String[] args ) throws Exception{
    BufferedReader br =new BufferedReader( new FileReader( "abc.java " ) );
    BufferedWriter bw = new BufferedWriter( new FileWriter( "abc.java " ) );
    String s = br.readLine();
    br.close();
    String w = "abc.java";
    bw.write( w );
  }
}

解决方案 »

  1.   

    补充一下,在
    bw.write( w );
    后面加上一句
    bw.close();
      

  2.   

    File file = new File("d:/websrc/a.txt");
    BufferedWriter write = new BufferedWriter(new FileWriter(file));
    String str = "lajdogfjawoij;asoidf";
    write.write(str,0,str.length());
    write.flush();
    write.close();BufferedReader read = new BufferedReader(new FileReader(file));
    String str2 = null;
    while((str2 = read.readLine())!=null){
    System.out.println(str2);
    }
    read.close();
      

  3.   

    作  者:  wobensuren (丑得杀死你)  
    等  级:    ^^^^
    四条内裤的老大啊
      

  4.   

    import java.io.*;
     import java.lang.*;
     public class ReadFile
       {
      public static void main(String args[]) throws Exception
        {
        FileReader br=new FileReader("test.txt");
        PrintWriter bw=new PrintWriter(new FileWriter("www.txt"));
        char  s;
    String ss;
       int t;
        while(br.ready()){
           t=br.read();
           char c;
           c=(char)t;
           ss=s+"";
           bw.write(s);
           bw.flush();
        }
      }
    }
      

  5.   

    package gkgl.basic;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import javax.servlet.*;
    //import javax.servlet.http.*;/**
    *提取参数的通用类*@author aa
    *Made in Zhengzhou.ha.china
    *datetime 2002.5.23
    */
    public class GetIni{/**
    *定义提取参数的通用方法
    *@param ininame 配置名称
    *@return 执行成功返回配置内容 否则返回"error"
    */
    public String getini(String ininame){
      InputStream is = getClass().getResourceAsStream("/gkgl/basic/db.properties");
      Properties dbProps = new Properties();
      try {
        dbProps.load(is);
      }catch (Exception e) {
        System.err.println("不能读取属性文件. " + "请确保db.properties在CLASSPATH指定的路径中");
        return "error";
      }//end try
      String iniString = dbProps.getProperty(ininame, "DBConnectionManager.log");
      return iniString;
    }//end public getini/**
    *定义提取数据库连接参数的通用方法
    *@param ininame 配置名称
    *@return 执行成功返回配置内容(数组型:Url,Conn,User,PassWd) 否则返回"error"
    */
    public String[] GetDatainis(String ininame){
      String[] iniString = new String[4];
      InputStream is = getClass().getResourceAsStream("/gkgl/basic/db.properties");
      Properties dbProps = new Properties();
      try {
        dbProps.load(is);
      }catch (Exception e) {
      System.err.println("不能读取属性文件. " + "请确保db.properties在CLASSPATH指定的路径中");
      iniString = null;
      return iniString;
      }//end try
      iniString[0] = dbProps.getProperty(ininame+".Url", "reading error");
      iniString[1] = dbProps.getProperty(ininame+".Conn", "reading error");
      iniString[2] = dbProps.getProperty(ininame+".User", "reading error");
      iniString[3] = dbProps.getProperty(ininame+".PassWd", "reading error");
      return iniString;
    }//end public getini  /**
       * 提取指标代码对应的该指标税务机关汇总结果URL
       * @param config ServletConfig
       * @filename 需要载入的文本文件名
       * @return Properties类型的值
       */
      public Properties getZbdmSwjghz(ServletConfig config,String filename) {
        try {
      String absPath=config.getServletContext().getRealPath("/property_files/"+filename);
      FileInputStream fis=new FileInputStream(absPath);
      Properties p=new Properties();
      p.load(fis);
      return p;
        } catch (Exception e) {
      e.printStackTrace();
      return null;
        }
      }}
      

  6.   

    读写
    not only read
    but also writeWhy not use RandomAccessFile ??somebody write a sample code,please!
      

  7.   

    import java.io.*;
    import java.util.*;class ModifyFileContent {
      public static void main(String[] args) throws IOException {
        String pwd = "222";
        String modifiedLine = "";
        String line = "";
        RandomAccessFile file = new RandomAccessFile("user.txt", "rw");
        long fileOffset = file.getFilePointer();    while ( (line = file.readLine()) != null) {
          StringTokenizer st = new StringTokenizer(line);      while (st.nextToken().equals("c")) {
            modifiedLine += "a" + "   " + st.nextToken() + "   " + pwd;
            System.out.println(modifiedLine);
            file.seek(fileOffset);
            file.writeBytes(modifiedLine);
          }
          fileOffset = file.getFilePointer();
        }  }
    }/*user.txt的内容是
    a   1   111
    b   2   222 
    c   3   333
    */以上程序可以修改最后的333为222