0
之間的字符串
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class excersie2
{
@SuppressWarnings("resource")
public static void main(String[] args) throws FileNotFoundException
{
ArrayList<String> titles = new ArrayList<String>();
ArrayList<String> titlestwo = new ArrayList<String>();
String path = "C:\\Users\\T-450s\\Desktop\\showtimes.txt";
File showtimes = new File(path);
Scanner fileReader = new Scanner(showtimes);
PrintWriter writer = new PrintWriter("C:\\Users\\T-450s\\Desktop\\output.txt");
while(fileReader.hasNextLine())
{
titles.add(fileReader.nextLine());
}
String movie = "";
for(String title : titles)
{
movie = title.substring((title.indexOf("\"")+1), title.lastIndexOf("\""));
}
writer.println("\n" + movie);
writer.close();
}
}
讀取以下txt文件:獲取報價
Now Showing
Title: "Deadpool"
Duration: 1 hr 48 mins
Title: "Zoolander"
Duration: 1 hr 42 mins
Title: "Kung Fu Panda 3"
Duration: 1 hr 35 mins
and writes a new file containing:
Deadpool
Zoolaner
Kung Fu Panda 3
如何實現這一目標?我嘗試使用子字符串,但每次都會出錯。
會發生什麼沒有引號?或空行? –
爲什麼你的'writer.println'在循環之外? –
如何更改掃描儀的分辨率?例如scanner.useDelimiter(「\\」* \\ s +「); –