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));
}
}
Ïà¹ØÎĵµ£º
char[] cha = operator.toCharArray();
char ch = cha[0];
double sum = 0;
switch (ch) {
&nb ......
java.lang
Àà Process
java.lang.Object
java.lang.Process
--------------------------------------------------------------------------------
public abstract class Processextends ObjectProcessBuilder.start() ºÍ Runtime.exec ·½·¨´´½¨Ò»¸ö±¾»ú½ø³Ì£¬²¢·µ»Ø Process ×ÓÀàµÄÒ»¸öʵÀý£¬¸ÃʵÀý¿ÉÓÃÀ´¿ØÖ ......
JAVAÃæÊÔÌ⼯
1.Êý¾Ý¿â£¬±ÈÈç100Óû§Í¬Ê±À´·Ã£¬Òª²Éȡʲô¼¼Êõ½â¾ö£»(JDBC)
´ð£º¿É²ÉÓà ......
ÔÚʹÓÃJavaµÄʱºò£¬ÎÒÃǶ¼»áÓöµ½Ê¹Óü¯ºÏ£¨Collection£©µÄʱºò£¬µ«ÊÇJava APIÌṩÁ˶àÖÖ¼¯ºÏµÄʵÏÖ£¬ÎÒÔÚʹÓúÍÃæÊÔµÄʱºòƵ
ƵÓöµ½ÕâÑùµÄ“¾ñÔñ” ¡£ :£©£¨Ö÷Òª»¹ÊÇÃæÊÔµÄʱºò£©
¾Ã¶ø¾ÃÖ®£¬Ò²¾ÍÓÐÁËÒ»µãµãµÄÐĵÃÌå»á£¬Ð´³öÀ´ÒÔ¹©´ó¼ÒÌÖÂÛ ¡£
×ܵÄ˵À´£¬Java APIÖÐËùÓõļ¯ºÏÀ࣬¶¼ÊÇʵÏÖÁËCollection½Ó¿Ú£¬Ëû ......
ÀïÎÒÃÇ×öÒ»¸öÍêÕûµÄÀý×ÓÀ´ËµÃ÷Ï̲߳úÉúµÄ·½Ê½²»Í¬¶øÉú³ÉµÄÏ̵߳ÄÇø±ð£º
package debug;import java.io.*;import java.lang.Thread;class MyThread extends Thread{ public int x = 0; public void run(){ System.out.println(++x); }}class R implements Runnable{ private in ......