关于各容器的默认布局:JPanel:FlowLayout JFrame:BorderLayout JDialog:BorderLayout
关于处理事件所在的包:除了DocumentEvent类在javax.swing.event包 中,其余的都在java.awt.event包 中。JComponent类在javax.swing包中,因此其子类的那些组件如JButton等也在该包中。Container类在java.awt包 中。
JFrame创建的窗口默认是不可见的。
RandomAccessFile类的seek(long a)方法,将读写位置定位于距离文件开头a个字节处
在进行使用in.read()读取源的数据,并存入到缓冲数组时,返回的int型变量是该方法读取的字符数的数量。
import java.io.*;
public class lei {
public static void main(String args[]){
File file = new File("hello.txt");
byte [] b = "abcdef".getBytes();
try{
FileOutputStream out = new FileOutStream(file);
out.write(b);
FileInputStream in = new FileInputStream(file);
byte [] a = new byte[5];
int m = in.read(a,0,5);
String s1 = new String(a);
m = in.read(a,0,5);
System.out.printlf("%s,%d",s1,m); //abcde,1
}
catch(Exception exp){}
}
}
当被存入的数组a溢出后,它会被从头重新读入,并且是一个字符一个字符覆盖。
import java.io.*;
public class lei {
public static void main(String args[]){
File file = new File("hello.txt");
byte [] b = "abcdef".getBytes();
try{
FileOutputStream out = new FileOutStream(file);
out.write(b);
FileInputStream in = new FileInputStream(file);
byte [] a = new byte[5];
int m = in.read(a,0,5);
String s1 = new String(a);
m = in.read(a,0,5);
String s2 = new String(a);
System.out.printlf("%s,%s",s1,s2); //abcde,fbcde
}
catch(Exception exp){}
}
}
注意字符(字节)输入流中的read()和read(char[])的方法,其返回值差别非常大!read()方法只读一个字符,返回一个整数(可能是ascll码,若超过范围则数很大)。而read(char[])则返回读取的字符的个数。
import java.io.*;
public class lei {
public static void main(String args[]){
File file = new File("hello.txt"); //今天是个好日子
try {
FileReader in = new FileReader(file);
char c[]=new char[7];
int m =in.read(c);
System.out.println(m); //7
}
catch(IOException exp){}
}
}
如果使用read()方法:
import java.io.*;
public class lei {
public static void main(String args[]){
File file = new File("hello.txt"); //今天是个好日子
try {
FileReader in = new FileReader(file);
//char c[]=new char[7];
int m =in.read();
System.out.println((char)m); //今
//System.out.println((char)m) : 20170
}
catch(IOException exp){}
}
}