private void writefile(String filename, byte[] contents) {
System.out.println(filename);
try {
FileOutputStream fos = new FileOutputStream(filename);
fos.write(contents);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}private String readFile(String filename) throws FileNotFoundException {
System.out.println(filename);
FileInputStream fis=null;
fis=new FileInputStream(filename);
ByteArrayOutputStream out=new ByteArrayOutputStream();
int b;
try{
while((b=fis.read())!=-1){
out.write(b);
}
}catch(IOException e){
e.printStackTrace();
}
byte[] content=out.toByteArray();
return(new String(content));
}
如果有些保护的话 会抛异常 不知道是不是这个
System.out.println(filename);
try {
FileOutputStream fos = new FileOutputStream(filename);
fos.write(contents);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}private String readFile(String filename) throws FileNotFoundException {
System.out.println(filename);
FileInputStream fis=null;
fis=new FileInputStream(filename);
ByteArrayOutputStream out=new ByteArrayOutputStream();
int b;
try{
while((b=fis.read())!=-1){
out.write(b);
}
}catch(IOException e){
e.printStackTrace();
}
byte[] content=out.toByteArray();
return(new String(content));
}
如果有些保护的话 会抛异常 不知道是不是这个
fos.write(contents);
fos.flush();
fos.close();
FileInputStream fisnew FileInputStream(new File(filename));
ByteArrayOutputStream out=new ByteArrayOutputStream();
import java.io.*;public class Frame1
{
public static void main(String[] args)
{
byte b[] = {'a', 'b', 'c'};
String fileName = "ab.txt";
Frame1 f = new Frame1();
f.writefile(fileName, b);
try { System.out.println(f.readFile(fileName)); }
catch (Exception e) { e.printStackTrace(); }
} private void writefile(String filename, byte[] contents) {
try {
FileOutputStream fos = new FileOutputStream(filename);
fos.write(contents);
fos.flush();
fos.close();
}
catch (IOException e) { e.printStackTrace(); }
} private String readFile(String filename) throws FileNotFoundException {
FileInputStream fis = null;
fis = new FileInputStream(filename);
ByteArrayOutputStream out = new ByteArrayOutputStream();
int b;
try {
while ( (b = fis.read()) != -1) {
out.write(b);
}
}
catch (IOException e) {
e.printStackTrace();
}
byte[] content = out.toByteArray();
return (new String(content));
}}