sdfsafd 未整理
TxtWrite .java
package com.javaeye.lindows.io;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class TxtWrite {
/**
* 利用缓冲流写入文本
*/
public void bfWrite() {
FileOutputStream fos = null;
try {
fos = new FileOutputStream("D:\\workspace\\java\\src\\com\\javaeye\\lindows\\io\\文本写入.txt");
BufferedWriter bWriter = new BufferedWriter(new OutputStreamWriter(fos));
bWriter.write("你好!\n 我是xxx Lindows.iteye.com ");
bWriter.flush(); //刷新缓冲流
} catch (Exception e) {
e.printStackTrace();
} finally{
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
TxtWrite tWrite = new TxtWrite();
tWrite.bfWrite();
}
}
asdfdasfsf
TxtRead .java
package com.javaeye.lindows.io;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class TxtRead {
/*
* 利用缓冲流读取文件,比较高效
*/
public static StringBuffer sBuffer = new StringBuffer();
public void bfRead() {
FileInputStream fis = null;
try {
/* 写法一 直接路径
* fis = new FileInputStream("D:\\workspace\\java\\src\\com\\javaeye\\lindows\\io\\文本读取.txt");
* fis = new FileInputStream("D:/workspace/java/src/com/javaeye/lindows/io/文本读取.txt");
*
* 写法二 常量接口
*/
fis = new FileInputStream(Constant.READ_PATH);
BufferedReader bReader = new BufferedReader(new InputStreamReader(fis));
String s;
while ((s = bReader.readLine()) != null) {
System.out.println(s); //格式化打印
sBuffer.append(s);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
TxtRead tRead = new TxtRead();
tRead.bfRead();
System.out.println("---------------------------");
System.out.println(sBuffer); //非格式化打印
}
}
sadfsdf
Constants.java
package com.javaeye.lindows.io;
public interface Constant {
public static final String READ_PATH = "D:\\workspace\\java\\src\\com\\javaeye\\lindows\\io\\文本读取.txt";
public static final String WRITE_PATH = "D:\\workspace\\java\\src\\com\\javaeye\\lindows\\io\\文本写入.txt";
}
sadffssa
java如何远程访问一个共享目录
http://www.iteye.com/topic/276022
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.Date;
- import jcifs.smb.SmbFile;
- import jcifs.smb.SmbFileInputStream;
-
asdfsdfdsf
end