第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

閱讀文件時(shí)如何跳過(guò)某些文本區(qū)域?

閱讀文件時(shí)如何跳過(guò)某些文本區(qū)域?

森林海 2021-06-28 12:57:25
我正在閱讀一個(gè).txt文件,并希望在將結(jié)果放入StringBuilder.文本示例:以下 Bicycle 類是自行車的一種可能實(shí)現(xiàn):/* 自行車類 class Bicycle {int 節(jié)奏 = 0;整數(shù)速度 = 0; } */所以這就是我可以得出的結(jié)論:public class Main {public static BufferedReader in;public static StringBuilder stringBuilder = new StringBuilder();public static void main(String[] args) {    String input = "input_text.txt";    try {        in = new BufferedReader(new FileReader(input));    } catch (FileNotFoundException e) {        e.printStackTrace();    }    String inputText;    try {        while ((inputText = in.readLine()) != null) {            if (inputText.startsWith("/*")) {// The problem is there:                while (!inputText.endsWith("*/")) {                    int lengthLine = inputText.length();                    in.skip((long)lengthLine);                }            }                stringBuilder.append(inputText);        }    } catch (IOException e) {        e.printStackTrace();    }我得到了無(wú)限while循環(huán),無(wú)法跳到下一行。
查看完整描述

1 回答

?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊

您永遠(yuǎn)不會(huì)inputText在while循環(huán)中重置 的值,因此它永遠(yuǎn)不會(huì)以*/導(dǎo)致無(wú)限循環(huán)而結(jié)束。此外,在skip()遇到*/will 工作之前,您不需要使用該方法作為簡(jiǎn)單的閱讀行。嘗試將循環(huán)更改為:


 while (!inputText.endsWith("*/")) {       

        String temp = in.readLine();

        if(temp == null) {break;}

        inputText = temp;                                                           

 }

輸出:(打印StringBuilder)


The following Bicycle class is one possible implementation of a bicycle:


查看完整回答
反對(duì) 回復(fù) 2021-07-07
  • 1 回答
  • 0 關(guān)注
  • 212 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)