要那2种method才能完成:文件输入/输出  
给点例子

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【handsome2t】截止到2008-07-02 13:37:51的历史汇总数据(不包括此帖):
    发帖的总数量:1                        发帖的总分数:30                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:1                        未结的总分数:30                       
    结贴的百分比:0.00  %               结分的百分比:0.00  %                  
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    InputStream ins = new FileInputStream(new File("输入文件名"));
    OutputStream ous = new FileOutputStream(new File("输出文件名"));
    byte[] b = new byte[1024*8];
    while(ins.read(b)!=-1) {
       ous.write(b);
    }
    ous.flush();
    ous.close();
    ins.close();没运行测试,凑合看吧
      

  3.   


    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Date;import javax.swing.ImageIcon;public class Fileone { public static void main(String args[]){
       
      
      
      File file=new File("d:/yl.JPG");
      File file2=new File("d:/yll.JPG");
      
      FileInputStream fio=null;
      FileOutputStream fot=null;
      ImageIcon ii=null;
      try {
           fio=new FileInputStream(file);
           fot=new FileOutputStream(file2);
           byte [] io1=new byte[2048];
           int reads=0;
           
           while((reads=fio.read(io1, 0, 2048))>=0)
           {        
            System.out.println(reads+"======");
            fot.write(io1,0,reads);       
           }
           fio.close();
           fot.close();
           
       
      } catch (FileNotFoundException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      
      System.out.println("size----------"+file2.length());
      ii=new ImageIcon("D:/workspace/printstudio/filesystem/photo/20070208/02170bc2800.jpg.p");
      int height=ii.getIconHeight();
      int width=ii.getIconWidth();
      System.out.println("height"+height);
      System.out.println("width"+width);
      System.out.println("String"+ii.toString());
      
      
     }
      

  4.   

    http://www.java2000.net/forumdisplay.jsp?fid=73
    去这里看看有你要的东西
      

  5.   


        /**
         * 写文件
         * @param file 文件
         * @param str 内容
         */
        public static void writeToFile(File file, String str)
        {
            PrintWriter out = null;
            BufferedReader in = null;        try
            {
                if(!file.exists())
                {
                    file.createNewFile();
                }            in = new BufferedReader(new StringReader(str));
                out = new PrintWriter(new BufferedWriter(new FileWriter(file)));            for(String line; (line = in.readLine()) != null;)
                {
                    out.println(line);
                }
            }
            catch(IOException e)
            {
                e.printStackTrace();
            }
            finally
            {
                try
                {
                    if(in != null)
                    {
                        in.close();
                    }                if(out != null)
                    {
                        out.close();
                    }
                }
                catch(IOException e)
                {
                    e.printStackTrace();
                }
            }
        }    /**
         * 将文本内容追加到文件末尾
         * @param file 文件
         * @param content 需要追加的文本
         */
        public static void appendToFile(File file, String content)
        {
            FileOutputStream fos = null;        BufferedOutputStream buff = null;        try
            {
                fos = new FileOutputStream(file, true);
                buff = new BufferedOutputStream(fos);
                buff.write(content.getBytes());
                buff.flush();        }
            catch(IOException e)
            {
                e.printStackTrace();
            }
            finally
            {
                try
                {
                    if(buff != null)
                    {
                        buff.close();
                    }                if(fos != null)
                    {
                        fos.close();
                    }
                }
                catch(IOException e)
                {
                    e.printStackTrace();
                }
            }
        }    /**
         * 读取文件内容
         * @param path 文件路径
         * @return 文件内容
         */
        public static String getFileContent(String path)
        {
            StringBuffer text = new StringBuffer();
            File file = null;
            FileInputStream in = null;
            InputStreamReader isr = null;        try
            {
                file = new File(path);
                in = new FileInputStream(file);
                isr = new InputStreamReader(in);            for(int i = 0; i < file.length(); i++)
                {
                    text.append((char)isr.read());
                }
            }
            catch(FileNotFoundException e)
            {
                e.printStackTrace();
            }
            catch(IOException ioe)
            {
                ioe.printStackTrace();
            }
            finally
            {
                try
                {
                    if(isr != null)
                    {
                        isr.close();
                    }                if(in != null)
                    {
                        in.close();
                    }
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }        }        return text.toString();
        }
      

  6.   

    File file = new File("d://content/use.txt");
    FileInputStream fis = new FileInputStream(file);
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    String len = null;
    while ((len=br.readLine())!=null) {
            String str = br.readLine();
            
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    File file = new File("d:\\content");
    file.mkdir();
    FileOutputStream fos = new FileOutputStream("d://content//use.txt");
    PrintWriter pw = new PrintWriter(fos);
    String str = "success";
    pw.println(str);
    pw.close();
      

  7.   

    前几天有人发了个IOUtil,比这个全多了,自己找找