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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

森林海 2021-06-28 12:57:25
我正在閱讀一個.txt文件,并希望在將結(jié)果放入StringBuilder.文本示例:以下 Bicycle 類是自行車的一種可能實現(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();    }我得到了無限while循環(huán),無法跳到下一行。
查看完整描述

1 回答

?
楊__羊羊

TA貢獻1943條經(jīng)驗 獲得超7個贊

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


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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