java学习笔记
最近学习java的IO操作,现整理如下
1 输入输出
java的库将程序与输入有关的类都从InputStream继承,与输出有关的类都从OutStream继承。
以前没有掌握的相关类 SequenceInputStream 将两个或更多的inputStream 转换成单个对象使用。
2 增添属性和有用的接口
装饰器 : 利用层次化对象动态透明的增加单个对象的能力的做法叫做“装饰器”
3 输入
对一个文件进行输入操作,需要一个FileInputStream 对象,为提高速度需要对文件进行缓冲处理 BufferedInputStream ,为了以格式化的形式读取数据,我们使用了DataInputStream 来进行处理。
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(args[0])));
4 快速文件输入
class InFile extends DataInputStream {
public InFile(String fileName) throws FileNotFoundException{
super(new BufferedInputStream(new FileInputStream(fileName)));
}
public InFile(File file) throws FileNotFoundException{
super(new BufferedInputStream(new FileInputStream(file.getPath())));
}
}
这样设计可以避免每次重复够造 。
同样快速文件输出可以按照上述的格式进行构造。
5 Reader Writer
inputstream 是字节流 ,二reader是字符流 传递unicode 。
要使用readLine()应该使用BufferedReader ,二不应该再使用DataInputStream
6 重导向标准IO package cn.bupt.io;
import java.io.*;
public class Redirect {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedInputStream in = null ;
try {
in = new BufferedInputStream(new FileInputStream(args[0]));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
PrintStream out = null ;
try {
out = new PrintStream(new BufferedOutputStream(new FileOutputStream(args[1]))) ;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.setIn(in) ;
System.setOut(out) ;
System.setErr(out) ;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = null ;
try {
whil
相关文档:
java中字符串和整型之间的转化
1)如何将字符串转化为整型;
int i = Integer.parseInt(String str);
int i = Integer.valueOf().intValue();
注:Integer.parseIn 和 Integer.valueOf 不同,前者生成的是整型,而后者是一个对象,所以要通过intValue()来获得对象的值;
&nb ......
Java的数据结构有哪些?Map与Set的本质区别是什么?
分析:Java常见的数据结构有Collection和Map,其中Collection接口下包括List和Set接口,其下又有多个实现类如List下有ArrayList、LinkedList和Vector等实现类,Set下有HashSet、LinkedSet等实现类和SortedSet接口,HashSet下有LinkedHashSet子类,SortedSet接口下有Tre ......
要想学好Java,首先要知道Java的大致分类。我们知道,自从Sun推出Java以来,就力图使之无所不包,所以Java发展到现在,按应用来分主要 分为三大块:J2SE,J2ME和 J2EE,这也就是Sun ONE(Open Net Environment)体系。J2SE就是Java2的标准版,主要用于桌面应用软件的编程;J2ME主要应用于嵌入是系统开发,如手机和PDA的编 程; ......
One:14109
Two:14000
Three:15141
four:14297
package com.zbalpha.test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ListTest {
public static void main(String args[]){
List<Long> ......
这段时间开始学习写存储过程,主要原因还是因为工作需要吧,本来以为很简单的,但几经挫折,豪气消磨殆尽,但总算搞通了,为了避免后来者少走弯路,特记述与此,同时亦对自己进行鼓励。
一:无返回值的存储过程
存储过程为:
CREATE OR REPLACE PROCEDURE TESTA(PARA1 IN VARCHAR2,PARA2 IN VARCHAR2) AS
BEGIN
......