java文件流处理 读取 配置文件

 

                try {
                    FileWriter filewriter = new FileWriter(
                            new File("f:/1.txt"), true);
                    String content = text_1.getText();
                    filewriter.write(content);
                    filewriter.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }

 

 

        InputStream in = Config.class.getResourceAsStream("/config/config.properties");
        try {
            p.load(in);
        } catch (Exception e) {
            throw new RuntimeException("error when try read config:"+property);
        }

 

配置文件应该放在/src/config/config.properties   

/config/config.properties    第一个/指的应该就是classpath的root, 即源码的src目录

 

 

 

 

                File f2 = new File("E:/99.inc");
                InputStreamReader read = null;
                try {
                    read = new InputStreamReader(new FileInputStream(f2),
                            "UTF-8");
                } catch (UnsupportedEncodingException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (FileNotFoundException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                BufferedReader reader2 = new BufferedReader(read);
                String line2;
                try {
                    while ((line2 = reader2.readLine()) != null) {
                        System.out.println(line2);
                    }
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

 

 

 

        File f = new File("/Users/aaa.txt");
        String strContent = "";
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(f));
            String line;
            while ((line = reader.readLine()) != null) {
                strContent += line;
            }
            System.out.println(strContent);
        } catch (FileNotFoundException e2) {
            e2.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if (reader!=null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

 

 

utf-8   

BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(fileName),"UTF-8")); 

你可能感兴趣的:(java,F#)