char str[4];
str[0] = (char)(a & 0xff);
str[1] = (char)((a > > 8) & 0xff);
str[2] = (char)((a > > 16) & 0xff);
str[3] = (char)((a > > 24) & 0xff);
将字符型转换字符串
通过String.valueOf(char)函数把字符转化成字符串
举例
char a='A';//定义一个字符a String str = String.valueOf(a);//把字符a转换成字符串str
最简单的方法 char c = 'a'; String s = "" + c;
char[ ]转String
String str = String.valueOf(char[] data);
把字符串转化为输入流
public static InputStream getStringStream(String sInputString){if (sInputString != null && !sInputString.trim().equals("")){
try{
ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(sInputString.getBytes());
return tInputStringStream;
}catch (Exception ex){
ex.printStackTrace();
}
}
return null;
}
//
//txt为TextArea内的字符串 try{ InputStream myIn=new ByteArrayInputStream(txt.getBytes("UTF-8")); //将System.in转化为面向字符的流 InputStreamReader ir = new InputStreamReader(myIn); in = new BufferedReader(ir);//为输入流提供缓冲区 while ((s = in.readLine()) != "bye") System.out.println("Read: " + s); } catch(IOException e) {System.out.println("Error! ");} }//
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
class ReadByte {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new FileReader(
"c:/bsmain_runtime.log"));
String s;
while (br.ready() && (s = br.readLine()) != "bye") {
System.out.println("Read: " + s);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
以上是直接从文件
===================
一下是从String
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;
import java.io.PrintWriter;
class ReadByte {
public static void main(String[] args) {
try {
String test = "1234\r\nsdfs";
PipedWriter pw = new PipedWriter();
PipedReader pr = new PipedReader(pw);
PrintWriter pw2 = new PrintWriter(new BufferedWriter(pw), true);
BufferedReader br = new BufferedReader(pr);
pw2.println(test);
String s;
while (br.ready() && (s = br.readLine()) != "bye") {

System.out.println("Read: " + s);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}