Java°´Ö¸¶¨ÐÐÊý¶ÁÈ¡Îļþ
package test
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
public class ReadSelectedLine{
// ¶ÁÈ¡ÎļþÖ¸¶¨ÐС£
static void readAppointedLineNumber(File sourceFile, int lineNumber)
throws IOException {
FileReader in = new FileReader(sourceFile);
LineNumberReader reader = new LineNumberReader(in);
String s = "";
if (lineNumber <= 0 || lineNumber > getTotalLines(sourceFile)) {
System.out.println("²»ÔÚÎļþµÄÐÐÊý·¶Î§(1ÖÁ×ÜÐÐÊý)Ö®ÄÚ¡£");
System.exit(0);
}
int lines = 0;
while (s != null) {
lines++;
s = reader.readLine();
if((lines - lineNumber) == 0) {
System.out.println(s);
System.exit(0);
}
}
reader.close();
in.close();
}
// ÎļþÄÚÈݵÄ×ÜÐÐÊý¡£
static int getTotalLines(File file) throws IOException {
FileReader in = new FileReader(file);
LineNumberReader reader = new LineNumberReader(in);
String s = reader.readLine();
int lines = 0;
while (s != null) {
lines++;
s = reader.readLine();
}
reader.close();
in.close();
return lines;
}
/**
* ¶ÁÈ¡ÎļþÖ¸¶¨ÐС£
*/
public static void main(String[] args) throws IOException {
// Ö¸¶¨¶ÁÈ¡µÄÐкÅ
int lineNumber = 2;
// ¶ÁÈ¡Îļþ
File sourceFile = new File("D:/java/test.txt");
// ¶Áȡָ¶¨µÄÐÐ
readAppointedLineNumber(sourceFile, lineNumber);
// »ñÈ¡ÎļþµÄÄÚÈݵÄ×ÜÐÐÊý
System.out.println(getTotalLines(sourceFile));
}
}
Ïà¹ØÎĵµ£º
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔǰ£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......
package ch01;
2
3public class BubbleSort
4{
5
6
7 public static void main(String[] args){
8 int[]& ......
JDKΪ³ÌÐòÔ±ÌṩÁË´óÁ¿µÄÀà¿â£¬¶øÎªÁ˱£³ÖÀà¿âµÄ¿ÉÖØÓÃÐÔ£¬¿ÉÀ©Õ¹ÐÔºÍÁé»îÐÔ£¬ÆäÖÐʹÓõ½ÁË´óÁ¿µÄÉè¼ÆÄ£Ê½£¬±¾ÎĽ«½éÉÜJDKµÄI/O°üÖÐʹÓõ½µÄDecoratorģʽ£¬²¢ÔËÓôËģʽ£¬ÊµÏÖÒ»¸öеÄÊä³öÁ÷Àà¡£
¡¡¡¡Decoratorģʽ¼ò½é
¡¡¡¡DecoratorģʽÓÖÃû°ü×°Æ÷(Wrapper)£¬ËüµÄÖ÷ÒªÓÃ;ÔÚÓÚ¸øÒ»¸ö¶ÔÏó¶¯Ì¬µÄÌí¼ÓһЩ¶îÍâµÄÖ°Ôð¡£Ó ......
JAVAÃæÊÔÌ⼯
1.Êý¾Ý¿â£¬±ÈÈç100Óû§Í¬Ê±À´·Ã£¬Òª²Éȡʲô¼¼Êõ½â¾ö£»(JDBC)
´ð£º¿É²ÉÓà ......
Õª×Ô£ºÇ§Àï±ù·â
/*
* CaptureScreen.java
*
* Created on 2007Äê8ÔÂ30ÈÕ, ÏÂÎç12:46
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package hadeslee.swing;
/**
*
* @author lbf
* ......