首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

已知E:\uplod目录下有一个.txt文件,如何把它转化成Byte数组呢?(急)

2012-01-15 
已知E:\uplod目录下有一个.txt文件,怎么把它转化成Byte数组呢?(急)有getByte方法吗[解决办法]getBytes()[

已知E:\uplod目录下有一个.txt文件,怎么把它转化成Byte数组呢?(急)
有   getByte方法吗

[解决办法]
getBytes();
[解决办法]
public void readToBuffer(StringBuffer buffer, InputStream is)
throws IOException {
String line; // 用来保存每行读取的内容
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
line = reader.readLine(); // 读取第一行
while (line != null) { // 如果 line 为空说明读完了
buffer.append(line); // 将读到的内容添加到 buffer 中
buffer.append( "\n "); // 添加换行符
line = reader.readLine(); // 读取下一行
}
}
调用:
InputStream is = new FileInputStream( "E:\\test.txt ");
StringBuffer buffer = new StringBuffer();
test.readToBuffer(buffer, is);
byte[] buf=buffer.toString().getBytes();


[解决办法]
来晚了

热点排行
Bad Request.