当前位置: 技术问答>java相关
求一个读取二进制文件并将内容转换成ASCII显示在屏幕上或写入文件的程序。谢了!
来源: 互联网 发布时间:2017-04-08
本文导语: 求一个读取二进制文件并将内容转换成ASCII显示在屏幕上或写入文件的程序。谢了! | java.sql.Statement stmt = con.createStatement(); ResultSet r = stmt.executeQuery("SELECT x FROM Table2"); // 现在以 4K 块...
求一个读取二进制文件并将内容转换成ASCII显示在屏幕上或写入文件的程序。谢了!
|
java.sql.Statement stmt = con.createStatement();
ResultSet r = stmt.executeQuery("SELECT x FROM Table2");
// 现在以 4K 块大小获取列 1 结果:
byte buff = new byte[4096];
while (r.next()) {
Java.io.InputStream fin = r.getAsciiStream(1);
for (;;) {
int size = fin.read(buff);
if (size == -1) { // 到达流末尾
break;
}
// 将新填充的缓冲区发送到 ASCII 输出流:
output.write(buff, 0, size);
ResultSet r = stmt.executeQuery("SELECT x FROM Table2");
// 现在以 4K 块大小获取列 1 结果:
byte buff = new byte[4096];
while (r.next()) {
Java.io.InputStream fin = r.getAsciiStream(1);
for (;;) {
int size = fin.read(buff);
if (size == -1) { // 到达流末尾
break;
}
// 将新填充的缓冲区发送到 ASCII 输出流:
output.write(buff, 0, size);
|
import java.io.*;
public class bin2asc2
{
public static void main( String[] args )
{
try
{
File f = new File("ran.class");
FileInputStream fis = new FileInputStream(f);
int i;
while ((i = fis.read()) != -1 )
{
char c = (char)i;
System.out.println(c);
}
}
catch (IOException e)
{
e.printStackTrace ();
}
}
}
public class bin2asc2
{
public static void main( String[] args )
{
try
{
File f = new File("ran.class");
FileInputStream fis = new FileInputStream(f);
int i;
while ((i = fis.read()) != -1 )
{
char c = (char)i;
System.out.println(c);
}
}
catch (IOException e)
{
e.printStackTrace ();
}
}
}
|
直接用
File file = new File("...");
BufferedReader in = new BufferedReader(
new InputStreamReader(
new FileInputStream(file)
)
);
用in.readLine()读
行吗?
File file = new File("...");
BufferedReader in = new BufferedReader(
new InputStreamReader(
new FileInputStream(file)
)
);
用in.readLine()读
行吗?
|
每一个字节转换成一个char