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

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

Java "while != null" 讀取最后一行為 null

Java "while != null" 讀取最后一行為 null

森林海 2023-03-02 10:23:45
我正在嘗試使用 URL 的批處理文件運(yùn)行以下代碼,而 URL 不為空。它完全按照我想要的方式運(yùn)行,但是,輸出的最后一行是:格式錯(cuò)誤的 URL 異常:“null”不是有效輸入批處理程序成功完成我希望程序在實(shí)際讀取 null 之前立即停止。有什么建議么?(此外,我仍在學(xué)習(xí)如何提問而不讓人們生我的氣,所以如果我可以改進(jìn)我的問題,請(qǐng)告訴我而不是投反對(duì)票。謝謝。)private static String getBatchUrlContents(String filePath) {        logger.debug(">>getBatchUrlContents()");        String theUrl = "";        try {            FileReader fileReader = new FileReader(filePath);            BufferedReader bufferedUrlReader = new BufferedReader(fileReader);            do {                try {                    theUrl = bufferedUrlReader.readLine();                    URL url = new URL(theUrl);                    HttpURLConnection urlConnection = (HttpURLConnection)  url.openConnection();                urlConnection.setRequestMethod("GET");                String contentType = urlConnection.getContentType();                logger.info("Content Type: {}", contentType);                int statusCode = urlConnection.getResponseCode();                logger.info("Status Code: {}", statusCode);                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));                String line;                List<String> contents = new ArrayList<String>();                 while ((line = bufferedReader.readLine()) != null) {                    contents.add(line);                }                bufferedReader.close();                String[] contentArray = contents.toArray(new String[contents.size()]);                System.out.println("\n ~~~~~~~NEW URL~~~~~~~ \n" + theUrl);                for (String x :contentArray)                    System.out.println(x);                String firstLine = contentArray[0];                if (firstLine.equals("#EXTM3U")) {                    logger.info("First line is validated: {}", firstLine);                    System.out.println("First line of content is validated: " + firstLine);                } 
查看完整描述

1 回答

?
翻翻過去那場雪

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

檢查theUrl != null發(fā)生在循環(huán)結(jié)束時(shí);它不是連續(xù)檢查的。


如果您需要theURL非 - null,則需要檢查一下。


您可以在條件下進(jìn)行分配(盡管這在某些圈子中不受歡迎):


while((theUrl = bufferedUrlReader.readLine()) != null) {

    URL url = new URL(theUrl);

    ...

或者,只需在循環(huán)內(nèi)進(jìn)行檢查并進(jìn)行手動(dòng)操作break:


while(true) {

    theUrl = bufferedUrlReader.readLine();


    if (!theURL) { // Or "if (theURL == null)"

        break;

    }


    URL url = new URL(theUrl);

    ...


查看完整回答
反對(duì) 回復(fù) 2023-03-02
  • 1 回答
  • 0 關(guān)注
  • 149 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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