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));
}
}
Ïà¹ØÎĵµ£º
Ò»£º×¼±¸ www.savarese.org download
1. rocksaw-1.0.0-src.tar.gz
2. vserv-tcpip-0.9.2-src.tar.gz
¶þ£º±àÒëÔ´ÎļþµÃµ½jar°ü ʹÓÃAnt
1. build vserv-tcpip-0.9.2-src
ÔÚvserv-tcpip-0.9.2Ŀ¼ÏÂÃæ½¨Ò»¸ötestsĿ¼£¬È»ºóÔÚcmd´°¿ÚϽøÈë ......
Ò»¡¢ÃæÏò¶ÔÏóµÄÌØÕ÷ÓÐÄÄЩ·½Ãæ
1.³éÏó£º
³éÏó¾ÍÊǺöÂÔÒ»¸öÖ÷ÌâÖÐÓ뵱ǰĿ±êÎ޹صÄÄÇЩ·½Ã棬ÒÔ±ã¸ü³ä·ÖµØ×¢ÒâÓ뵱ǰĿ±êÓйصķ½Ãæ¡£³éÏó²¢²»´òËãÁ˽âÈ«²¿ÎÊÌ⣬¶øÖ»ÊÇÑ¡ÔñÆäÖеÄÒ»²¿·Ö£¬ÔÝʱ²»Óò¿·Öϸ½Ú¡£³éÏó°üÀ¨Á½¸ö·½Ã棬һÊǹý³Ì³éÏ󣬶þÊÇÊý¾Ý³éÏó¡£
2 ......
JDKΪ³ÌÐòÔ±ÌṩÁË´óÁ¿µÄÀà¿â£¬¶øÎªÁ˱£³ÖÀà¿âµÄ¿ÉÖØÓÃÐÔ£¬¿ÉÀ©Õ¹ÐÔºÍÁé»îÐÔ£¬ÆäÖÐʹÓõ½ÁË´óÁ¿µÄÉè¼ÆÄ£Ê½£¬±¾ÎĽ«½éÉÜJDKµÄI/O°üÖÐʹÓõ½µÄDecoratorģʽ£¬²¢ÔËÓôËģʽ£¬ÊµÏÖÒ»¸öеÄÊä³öÁ÷Àà¡£
¡¡¡¡Decoratorģʽ¼ò½é
¡¡¡¡DecoratorģʽÓÖÃû°ü×°Æ÷(Wrapper)£¬ËüµÄÖ÷ÒªÓÃ;ÔÚÓÚ¸øÒ»¸ö¶ÔÏó¶¯Ì¬µÄÌí¼ÓһЩ¶îÍâµÄÖ°Ôð¡£Ó ......
Õª×Ô£ºÇ§Àï±ù·â
/*
* 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
* ......