IO流筆記:
Reader Writer (抽象類,不可以實例化)
Readerr=new FileRader("路徑");
Writer w =new FileWriter("路徑");
字符流可以拷貝由字符組成的文件,字節(jié)流被字符流拷貝,會損壞其文件
轉(zhuǎn)換流: (字節(jié)轉(zhuǎn)字符)
InputStream is = new FileInputStream("c:/aaa.txt");
Reader reader = new InputStreamReader(is);
OutputStream os = new FileOutputStream("c:/bbb.txt");
Writer writer = new OutputStreamWriter(os);
緩沖流:BufferedReader reader.readLine();讀一行 大大的提高讀的效率
BufferedWriter writer.Writer();寫一行,newLine();換行
打印流 PrintWriter
操作字符數(shù)組流:CharArrayReader和CharArrayWriter
使用完流需要關(guān)閉
數(shù)據(jù)庫存儲大型文件 byte[]數(shù)組 數(shù)據(jù)庫的字段。。。。
存儲大的圖像,音樂,視頻(數(shù)據(jù)庫的字段設(shè)置成)
tinyblob 28--1B(256B)
blob 216-1B(64K)
mediumblob 224-1B(16M)
longblob 232-1B(4G)
存儲大型文本(數(shù)據(jù)庫的字段設(shè)置成)
tinytext 28--1B(256B)
text 216-1B(64K)
mediumtext 224-1B(16M)
longtext 232-1B(4G)
Properties文件
可以放在src下或者放在包下,#號注釋,里面的中文衛(wèi)\+16進(jìn)制
兩種獲得方式:
第一種方式
Preperties 去獲得 Preperties p=new Preperties();
InputStream in=new FileInputStream("preproties文件路徑")
p.load(in);
或者是 InputStream in= 類名.class.getClassLoader().getResourceAsStream(preproties文件路徑);
preproties文件路徑,如果在src下,不用寫包名,直接文件名+后綴,如果在包下,需要寫包名+文件名+后綴 例如:com/salmon/test.preproties
String name = p.getProperty("zrgk.user.name");
String pwd = p.getProperty("zrgk.user.password");
String addr = p.getProperty("zrgk.user.address");
System.out.println(name);
System.out.println(pwd);
System.out.println(addr);
第二種方式:
//ResourceBundle rb = ResourceBundle.getBundle("test"); //不能寫文件后綴名
//ResourceBundle rb = ResourceBundle.getBundle("com/zrgk/config/test");
ResourceBundle rb = ResourceBundle.getBundle("com.zrgk.config.test");
System.out.println(rb.getString("zrgk.user.name"));
System.out.println(rb.getString("zrgk.user.password"));
System.out.println(rb.getString("zrgk.user.address"));
取值的時候,獲取key值要和properties文件中的key保持一致
修改jdbc中的加載驅(qū)動,連接,用戶名,密碼
在properties文件中:
加載驅(qū)動:driverClassName=com.mysql.jdbc.Driver
數(shù)據(jù)庫連接:url=jdbc:mysql://127.0.0.1:3306/數(shù)據(jù)庫名
用戶名: username: 連接數(shù)據(jù)庫的用戶名
密碼 password: 連接數(shù)據(jù)庫的密碼
在封裝的類中
private static String driverClassName;
private static String url;
private static String username;
private static String password;
static {
try {
ResourceBundle rb=ResourceBundle.getBundle("jdbc");
driverClassName = rb.getString("driverClassName");
url=rb.getString("url");
username=rb.getString("username");
password=rb.getString("password");
//獲得驅(qū)動
Class.forName(driverClassName);
} catch (ClassNotFoundException e) {
// TODO 自動生成的 catch 塊
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection conn =null;
try {
conn = DriverManager.getConnection(url, username, password);
} catch (SQLException e) {
// TODO 自動生成的 catch 塊
e.printStackTrace();
}
return conn;
}