package com.parse.demo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
public class BufferReaderDemoClass {
/**
* @param args
*/
public static void main(String[] args) {
InputStream ins;
try {
ins = new FileInputStream(new File("D:\\android_config.xml"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
// TODO Auto-generated method stub
String out = null;
StringBuffer output = null;
BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
int read;
char[] buffer = new char[4096];
output = new StringBuffer();
try {
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String bufferString =output.toString();
File file = new File("D:\\android_config_demo.xml");
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
PrintStream ps = null;
try {
ps = new PrintStream(new FileOutputStream(file));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ps.println(bufferString);// 往文件里写入字符串
ps.close();
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
public class BufferReaderDemoClass {
/**
* @param args
*/
public static void main(String[] args) {
InputStream ins;
try {
ins = new FileInputStream(new File("D:\\android_config.xml"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
// TODO Auto-generated method stub
String out = null;
StringBuffer output = null;
BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
int read;
char[] buffer = new char[4096];
output = new StringBuffer();
try {
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String bufferString =output.toString();
File file = new File("D:\\android_config_demo.xml");
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
PrintStream ps = null;
try {
ps = new PrintStream(new FileOutputStream(file));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ps.println(bufferString);// 往文件里写入字符串
ps.close();
}
}