BufferedReader
DataInputStream/DataOutputStream
RandomAccessFile: 依靠seek()方法在文件中到处移动。
被BlockQueue代替了
SequenceInputStream(intpuStre)
InputStream: System.in
PrintStream: System.out、System.err
System.setIn(InputStream),
System.setOut(PrintStream),
System.setErr(PrintStream) 进行标准I/O重定向
new IO
public class IntBufferDemo {
private static int BSIZE = 1024;
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.allocCate(BSIZE);
IntBuffer ib = bb.asIntBuffer();
ib.put(new int[]{11, 23, 23. 25. 35, 66, 122, 89});
System.out.println(ib.get(3));
ib.put(3, 889);
ib.filp();
while(ib.hasRemaining()) {
int i = ib.get(3);
System.out.printlb(i);
}
}
}
|0|0|0|0|0|0|0|0| bytes
| | | | a | chars
| 0 | 0 | 0 | 0 | shorts
| 0 | 97 | ints
| 0.0 |1.3E-44| floats
| 97 | longs
| 1.3E-322 | doubles
public class LargeMappedFiles {
static int length = 0x8FFFFFF;/ 128MB
public static void main(String[] args) {
MappedByteBuffer out = new RandomAccessFile("test.dat", "rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length);
for (int i=0, i<length; i++) {
out.put((byte)'x');
}
System.out.print("finished writing");
for(int i = length /2; i < length/2 + 6; i++) {
System.out.printnb((char)out.get(i));
}
}
}
public class FileLoking {
public static void main(String[] args) {
FileOutputString fos = new FileOutputStream("test.txt");
FileLock fl = fos.getChannel().tryLock();
if(fl != null) {
System.out.println("locked file");
TimeUnit.MILLISECONDS.sleep(1000);
fl.release();
System.out.println("Release Lock");
}
fos.close();
}
}
对文件某一个部分上锁
tryLock(long position, long size, boolean shared); // 非阻塞
lock(long position, long size, boolean shared); // 阻塞
针对独占锁和共享锁由系统底层提供。
FileLock isShared();//查询所否为共享锁
还有一些网络通信方面的:NIO/BIO/AIO等等,均为通信层的内容。
参考资料:https://zhuanlan.zhihu.com/p/91808057
int i = 1;
double[] ds = [0.1, 0.3];
String str = "hello world";
// i.getClass(); int.class
// ds.getClass(); doutble[].class
str.getClass();
相关API:
java.lang.Class
static Class forName(String className)
Object newInstance()
java.lang.reflact.Constructor
Object newInstance(Object[] args)
java.lang.Class
Field getField(String name)
指定名称的公有域Field[] getFields()
当前类及父类的所有pulic
域Field getDeclaredField(String name)
当前类中声明的指定名称的域Field[] getDeclaredFields()
当前类的所有域Method[] getMethods()
Method[] getDeclareMethods()
Constructor[] getConstructors()
Constructor[] getDeclaredConstructors()
java.lang.reflact.Field
Class getDeclaringClass()
int getModifiers()
String getName()
java.lang.reflact.Method
Class getDeclaringClass()
int getModifiers()
String getName()
Class[] getExceptionTypes()
Class[] getParameterTypes()
Class getReturnType()
java.lang.reflact.Constructor
Class getDeclaringClass()
int getModifiers()
String getName()
Class[] getExceptionTypes()
Class[] getParameterTypes()
java.lang.reflact.Modifier
static String toString(int modifiers)
返回修饰符的字符串表示static boolean isAbstract(int modifiers)
static boolean isFinal(int modifiers)
static boolean isInterface(int modifiers)
static boolean isNative(int modifiers)
static boolean isPrivate(int modifiers)
static boolean isProtected(int modifiers)
static boolean isPublic(int modifiers)
static boolean isStatic(int modifiers)
static boolean isStrict(int modifiers)
如果整数参数包含strictfp
修饰符,则返回true
,否则返回false
。static boolean isSynchronized(int modifiers)
static boolean isVolatile(int modifiers)
static boolean isTransient(int mod)
java.lang.reflect.AccessibleObject
void setAccessible(boolean flag)
boolean isAccessible()
static void setAccessible(AccessibleObject[] array, boolean flag)
java.lang.reflect.Field
Object get(Object obj)
void set(Object obj, Object newValue)
public static void main(String[] args){
Employee[] a = new Employee[100];
...
a = (Employee[])arrayGrow(a);
}
static Object[] arrayGrow(Object[] a) {
int newLength = a.length * 11 / 10 + 10;
Object[] newArray = new Object[newLength];
System.arrayCopy(a, 0, newArray, 0, a。length);
return newArray;
}
static Object arryGrow(Object a) {
Class cl = a.getClass();
if( !cl.isArray()) {
return null;
}
Class componentType = c1.getComponentType()
int length = Array.getLength(a);
int newLength = length * 11 / 10 + 10;
Object newArray = Array.newInstance(componentType, newLength);
System.arrayCopy(a, 0, newArray, 0, length);
return newArray;
}
java.lang.reflect.Array
static Object get(Object array, int index)
static xxx getXxx(Object array, int index)
适用于:·boolean, byte, char, double, float, int long, short·static void set(Object array, int index, Object newValue)
static void setXxx(Object array, int intx, xxx newValue)
适用于:·boolean, byte, char, double, float, int long, short·static int getLength(Object array)
static Object newInstance(Class componentType, int length)
static Object newInstance(Class componentType, int[] lengths)
java.lang.reflect.Method
public Object invoke(Object implicictParameter, Object[] explicitparamenters)
调用这个对象所描述的方法,传递给定参数,并返回方法的返回值。
对于静态方法,把null作为隐式参数传递。
interface Foo {}
class MyFoo implements Foo {}
InvocationHandler handler = new InvocationHandler(...);
Class proxyClass = Proxy.getProxyClass(Foo.class.getClassLoader(), new Class[] { Foo.class });
Foo f = (Foo) proxyClass.getConstructor(new Class[] { InvocationHandler.class }).newInstance(new Object[] { handler });
// or
Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(), new Class[] { Foo.class }, handler);
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
class @interface Test{
}
1. 确定值
参考资料:
全部评论