首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java IO 字节流 字符源

2012-12-20 
Java IO 字节流 字符流package com.demoimport java.io.FileWriterimport java.io.IOExceptionpublic c

Java IO 字节流 字符流

package com.demo;import java.io.FileWriter;import java.io.IOException;public class ConfigureFileWriter {/** * @param args * @throws IOException * @throws IOException */public static void main(String[] args) {// TODO Auto-generated method stubFileWriter fileWriter = null;try {fileWriter = new FileWriter("conf.properties");fileWriter.write("dbDriver=oracle.jdbc.driver.OracleDriver");System.out.println("success");} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {if (fileWriter != null) {try {fileWriter.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}}

package com.demo;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;public class ConfigureFileReader {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubFileReader fileReader = null;try {fileReader = new FileReader("conf.properties");char[] chars = new char[64];int hasRead = 0;while ((hasRead = fileReader.read(chars)) > 0) {System.out.println(new String(chars, 0, hasRead));}} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {if (fileReader != null) {try {fileReader.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}}

package com.demo;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class ReadProperties {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubProperties props = new Properties();File f = new File("conf.properties");try {props.load(new FileInputStream(f));System.out.println(props.getProperty("dbDriver"));} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}  }}

热点排行