* 掃描控制檯輸入
*
* @author leizhimin 2009-7-24 11:24:47
*/
public class TestScanner {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("請輸入字符串:");
while (true) {
String line = s.nextLine();
if (line.equals("exit")) break;
System.out.println(">>>" + line);
}
}
}
234
>>>234
wer
>>>wer
bye
>>>bye
exit
Process finished with exit code 0
Scanner s = new Scanner("123 asdf sd 45 789 sdf asdfl,sdf.sdfl,asdf ......asdfkl las");
// s.useDelimiter(" |,|\\.");
while (s.hasNext()) {
System.out.println(s.next());
}
}
asdf
sd
45
789
sdf
asdfl,sdf.sdfl,asdf
......asdfkl
las
Process finished with exit code 0
asdf
sd
45
789
sdf
asdfl
sdf
sdfl
asdf
asdfkl
las
Process finished with exit code 0
返回此 Scanner 當前正在用於匹配分隔符的 Pattern。
hasNext()
判斷掃描器中當前掃描位置後是否還存在下一段。(原APIDoc的註釋很扯淡)
hasNextLine()
如果在此掃描器的輸入中存在另一行,則返回 true。
next()
查找並返回來自此掃描器的下一個完整標記。
nextLine()
此掃描器執行當前行,並返回跳過的輸入信息。
InputStream in = new FileInputStream(new File("C:\\AutoSubmit.java"));
Scanner s = new Scanner(in);
while(s.hasNextLine()){
System.out.println(s.nextLine());
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import com.verisign.uuid.UUID;
/**
* ��һ������թƭ��վ�Զ��ύ������Ϣ�ij����ÿտ�������һ�¡�
* @author wangpeng
*
*/
public class AutoSubmit {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
...在此省略N行
Process finished with exit code 0