import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Arrays;
public class Testchar {
public static void main(String[] args) throws IOException {
byte[] b = new byte[] { -50, -46 };
char c = '0';
String s = "我愿意今生唯一zhiyouni";
File file = new File("D://io//file.txt");
FileWriter raf = new FileWriter(file, true); // 带参数true从文件尾开始写,不带参数默认从头开始写
raf.write(s);// 写字符串
raf.write(c);//
raf.write((char) b[1]);//
raf.write(Arrays.toString(b));//
raf.write(new String(b));//
raf.flush();
raf.close();
System.out.println(Arrays.toString(s.getBytes()));// 字符串》字节数组》字符显示,显示为字符串s对应的每个字符(汉字2字节,英文1字节)的ASIC码
System.out.println(Arrays.toString(b));
System.out.println(new String(b));
System.out.println((char) b[1]);
System.out.println(b);
}
}
package IO;
import java.io.IOException;
import java.util.Arrays;
public class IoTest {
public static void main(String[] args) throws IOException {
int a = 1;
String s = new String("123牛振兴");
byte[] b = s.getBytes();
char[] c = s.toCharArray();
byte bb = b[0];
char cc = c[0];
System.out.println("a :"+a);
System.out.println("b :"+b);
System.out.println("c :"+c);
System.out.println("b.toString() :"+b.toString());
System.out.println("c.toString() :"+c.toString());
System.out.println("Arrays.toString(b) :"+Arrays.toString(b));
System.out.println("Arrays.toString(c) :"+Arrays.toString(c));
System.out.println("new String(s.getBytes()) :"+new String(s.getBytes()));
System.out.println("new String(s.toCharArray()) :"+new String(s.toCharArray()));
System.out.println("s :"+s);
System.out.println("bb :"+bb);
System.out.println("cc :"+cc);// out流继承自Printstream的方法
System.out.println(System.in);
System.out.write(a); System.out.println();
System.out.write(b); System.out.println();
// System.out.write(c);//out流继承自Printstream和FilterOutputStream方法
// System.out.write(s);
System.out.write(bb); System.out.println();
System.out.write(cc); System.out.println();
// System.out.write(System.in);
}
}