package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public static void main(String arg[]) {
String fileName = "E://share//test.txt";
File file = new File(fileName);
String writeData = "HelloWorld!/r/nnihao我的内存是2G的 ";
byte[] byteOutData = writeData.getBytes();
byte[] byteInData = new byte[20];
int length = 0;
if (file.isFile()) {
file.delete();
}
try {
if (file.createNewFile() && file.canWrite()) {
FileOutputStream fileOutStream = new FileOutputStream(file);
fileOutStream.write(byteOutData);
fileOutStream.close();
}
if (file.canRead()) {
FileInputStream fileInStream = new FileInputStream(file);
while ((length = fileInStream.read(byteInData)) != -1) {
System.out.print(new String(byteInData, 0, lenght));
}
fileInStream.close();
}
} catch (IOException e) {
System.out.println("IOException occur");
e.getMessage();
}
}
}