1个回答
展开全部
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public static void main(String[] args) {
BufferedOutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(new File("d:/info.txt")));
String line = "第一行文本\n第二行文本";
out.write(line.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream("d:/info.txt"));
StringBuffer buffer = new StringBuffer();
byte[] buff = new byte[in.available()];
while (in.read(buff) != -1) {
buffer.append(new String(buff));
}
System.out.println(buffer);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
in = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public static void main(String[] args) {
BufferedOutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(new File("d:/info.txt")));
String line = "第一行文本\n第二行文本";
out.write(line.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream("d:/info.txt"));
StringBuffer buffer = new StringBuffer();
byte[] buff = new byte[in.available()];
while (in.read(buff) != -1) {
buffer.append(new String(buff));
}
System.out.println(buffer);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
in = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询