Java读写文件.
简单实现. 以备后用.
package com.enorth.mpup.util;
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.OutputStream;
public class Log {
public void logFile(){
String filePath= "d://zzz/";
String fileName="log.txt";
File file = new File(filePath,fileName);
try {
InputStream is = new FileInputStream(file);
OutputStream os=new FileOutputStream("d://zzz/a.txt");
byte[] buffer=new byte[400];
int length=0;
while( (length=is.read(buffer)) > 0 ){
os.write(buffer, 0, length);
}
is.close();
// os.write("华师大金卡回答厉害的".getBytes()); //直接写
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Log log=new Log();
log.logFile();
}
}
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.OutputStream;
public class Log {
public void logFile(){
String filePath= "d://zzz/";
String fileName="log.txt";
File file = new File(filePath,fileName);
try {
InputStream is = new FileInputStream(file);
OutputStream os=new FileOutputStream("d://zzz/a.txt");
byte[] buffer=new byte[400];
int length=0;
while( (length=is.read(buffer)) > 0 ){
os.write(buffer, 0, length);
}
is.close();
// os.write("华师大金卡回答厉害的".getBytes()); //直接写
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Log log=new Log();
log.logFile();
}
}
本文转自chainli 51CTO博客,原文链接:http://blog.51cto.com/lichen/158325,如需转载请自行联系原作者