标题:怎么解决输入问题,信息自己输入怎么编啊
只看楼主
yueqi933
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-5-28
结帖率:100%
已结贴  问题点数:20 回复次数:1 
怎么解决输入问题,信息自己输入怎么编啊
import *;
class WriteFile{
    public boolean writeFile(String str,String path,int i){
        boolean check=true;
        if(i==0){
            check=false;
        }
        File fie=new File(path);
        try{
            FileWriter outFile=new FileWriter(fie,check);
            BufferedWriter bufferOut=new BufferedWriter(outFile);
            bufferOut.write(str);
            bufferOut.flush();
            bufferOut.close();
            return true;
        }
        catch (IOException e){return false;}
    }
}
class ReadFile{
    public boolean readFile(String path){
        int mancnt=0;
        int woncnt=0;
        float agemony=0;
        try{
            StringBuffer sb=new StringBuffer();
            BufferedReader br=new BufferedReader(new FileReader(path));
            String str=br.readLine();
            while(str !=null){
                sb.append(str);
                    sb.append("\r\n");
                    str=br.readLine();
            }
            str=sb.toString();
            System.out.println(str);
            String[] st=str.split("\r\n");
            for (int i=1;i<st.length;i++){
                String stl=st[i];
                if(stl.split("\\s{2,}")[1].equals("男"))
                    mancnt++;
                else
                    woncnt++;
                agemony+=Float.parseFloat(stl.split("\\s{1,}")[4]);
            }
            System.out.println("男员工数:'"+mancnt+"'");
            System.out.println("女员工数:'"+woncnt+"'");
            System.out.println("平均工资:'"+agemony/st.length+"'");
            return true;
        }
        catch(IOException e){
            return false;
        }
    }
}
public class OperatFile{
    public static void main(String[] args){
        boolean check=true;
        String[] str={
                "姓名 性别 年龄 学历  工资                     岗位",
                "约翰 男      30      硕士 100000.00        银行行长",
                "迈克 男      28      博士  200000.00       董事长",
                "詹尼 女      24      硕士  150000.00       主任"
        };
        String path="人员.txt";
        WriteFile wf=new WriteFile();
        ReadFile rf=new ReadFile();
        for(int i=0;i<str.length;i++){
            check=wf.writeFile(str[i], path, i);
            check=wf.writeFile("\r\n",path,1);
            if(!check){
                System.exit(1);
            }
        }
        System.out.println("写入文本文件成功!");
        rf.readFile(path);
    }
}
搜索更多相关主题的帖子: 信息 false import return public 
2013-06-05 00:23
xioun
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:68
专家分:309
注 册:2013-4-8
得分:20 
   */使用这个方法即可,(其实实现方法很多)
            public void fileWriter(String physical)
            {
                FileWriter fileWriter=null;
                File file=new File("");
                String path=file.getAbsolutePath();
                StringBuffer buffer=new StringBuffer(path);
                buffer.append("\\licensekey");
                try
                {
                  fileWriter=new FileWriter(buffer.toString());
                  fileWriter.write(physical);
                  fileWriter.flush();
                }catch(IOException e)
                {
                    e.printStackTrace();
                }finally
                {
                   if(fileWriter!=null)
                   {
                       try {
                          fileWriter.close();
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
                   }
                }
            }   

命若天定,我就破了这个天!
2013-06-05 08:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-414545-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026656 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved