FileReader读取出来的Char数组转换为字符串3种方法
来源:互联网 发布:金星 知乎 编辑:程序博客网 时间:2024/05/17 03:14
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.junit.Test;
public class Test_zifuliu {
@Test
public void test1() {
File file = new File("dbcp.txt");
FileReader fr = null;
try {
fr = new FileReader(file);
char[] cbuf = new char[1024];
int len = 0;
while ((len = fr.read(cbuf)) != -1) {
System.out.print(new String(cbuf)); //将char数组转换为String字符串3种方法
System.out.println(String.valueOf(cbuf));
StringBuffer sb=new StringBuffer();
sb.append(cbuf);
System.out.println(sb);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.junit.Test;
public class Test_zifuliu {
@Test
public void test1() {
File file = new File("dbcp.txt");
FileReader fr = null;
try {
fr = new FileReader(file);
char[] cbuf = new char[1024];
int len = 0;
while ((len = fr.read(cbuf)) != -1) {
System.out.print(new String(cbuf)); //将char数组转换为String字符串3种方法
System.out.println(String.valueOf(cbuf));
StringBuffer sb=new StringBuffer();
sb.append(cbuf);
System.out.println(sb);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
0 0
- FileReader读取出来的Char数组转换为字符串3种方法
- delphi字符串转换为char数组
- java FileReader的第二种读取方式read(char[])
- 字符串和char数组的相互转换
- 字符串数组|char *转换为unsigned int|友元
- 如何:将 char * 字符串转换为 System::Byte 数组
- 在Java中如何把char数组转换为字符串
- 如何将char[]数组转换为String字符串
- Java中char数组(字符数组)与字符串String类型的转换方法
- Java中char数组(字符数组)与字符串String类型的转换方法
- ORACLE 中字符串转换为数组的函数方法
- 把以',' 分隔的列转换为行,读取出来
- 把string转换为char* 的三种方法
- Unicode Cstring转换为Char*的几种方法
- char转换为string的方法
- jni 字符串转化为 char* 的方法
- [C++]char转换为string ,固定长度的char数组转换为string
- java 字符串转化为字符数组的3种方法
- andorid 5.0 permission出错 INSTALL_FAILED_DUPLICATE_PERMISSION
- Boyer-Moore算法java实现
- A+B和C
- Android工程依赖
- linux mysql安装
- FileReader读取出来的Char数组转换为字符串3种方法
- android小项目
- redmine 增加枚举类型
- linux下DNS服务器配置
- 浅谈MVC架构—你到底有什么本事
- 解决XFireFault: Server did not recognize the value of HTTP Header SOAPAction: .
- Perl中Schwartzian转换问题
- 从源代码的角度分析--在BaseAdapter调用notifyDataSetChanged()之后发生了什么
- JAVA Swt初识