urldissector.java
来自「Java 程序设计教程(第五版)EXAMPLESchap05源码」· Java 代码 · 共 40 行
JAVA
40 行
//********************************************************************
// URLDissector.java Author: Lewis/Loftus
//
// Demonstrates the use of Scanner to read file input and parse it
// using alternative delimiters.
//********************************************************************
import java.util.Scanner;
import java.io.*;
public class URLDissector
{
//-----------------------------------------------------------------
// Reads urls from a file and prints their path components.
//-----------------------------------------------------------------
public static void main (String[] args) throws IOException
{
String url;
Scanner fileScan, urlScan;
fileScan = new Scanner (new File("urls.inp"));
// Read and process each line of the file
while (fileScan.hasNext())
{
url = fileScan.nextLine();
System.out.println ("URL: " + url);
urlScan = new Scanner (url);
urlScan.useDelimiter("/");
// Print each part of the url
while (urlScan.hasNext())
System.out.println (" " + urlScan.next());
System.out.println();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?