Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package InputOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class InputOutputStream {
- public String readInfo(String path){
- String str = "";
- FileInputStream in = null;
- try{
- File f = new File(path);
- in = new FileInputStream(f);
- int i=0;
- while(( i=in.read())>0){
- char ch = (char) i;
- str += ch;
- }
- in.close();
- return str;
- }catch(Exception ex){
- Logger.getLogger(InputOutputStream.class.getName()).log(Level.SEVERE, null, ex);
- }
- return "";
- }
- public void write(String content, String path){
- FileOutputStream out = null;
- try{
- File f = new File(path);
- out = new FileOutputStream(f);
- char[] chs = content.toCharArray();
- for(char ch:chs){
- out.write((int)ch);
- }
- out.close();
- }catch(Exception ex){
- System.out.println("Loi khong the ghi file");
- }
- }
- public static void main(String arg[]) {
- InputOutputStream obj = new InputOutputStream();
- String str = obj.readInfo("C:/test.txt");
- obj.write(str, "D:/copy.txt");
- System.out.println("Da copy thanh cong noi dung sau: ");
- System.out.println(str);
- }
- }
Add Comment
Please, Sign In to add comment