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

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

Java Java中的空行

Java Java中的空行

SMILET 2021-05-06 10:10:20
 protected synchronized static void getRandomProxy(String srcFile) throws FileNotFoundException {        List<String> words = new ArrayList<>();         BufferedReader reader = null;        try {             reader = new BufferedReader(new FileReader(srcFile));            String line;            while ((line = reader.readLine()) != null) {                words.add(line);                System.out.println(line);            }            int k = 0;            for (int i = 0; i < words.size(); i++) {                k++;                String[] splitted = words.get(i).split(":");                String ip = splitted[0];                String port = splitted[splitted.length - 1];//                System.out.println(k + " " + ip + " * " + port);            }        } catch (IOException iOException) {        } finally {            try {                reader.close();            } catch (IOException ex) {               ex.printStackTrace();            }        }    }我想輸出沒有空行的輸出。這些結果越來越像:結果1。結果2。結果3。我想要像這樣的輸出:結果1.結果2.結果3。沒有空白行。
查看完整描述

3 回答

?
呼喚遠方

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

如果字符串為空,則不要將其添加到列表中:


if(!line.trim().isEmpty()) {

    words.add(line);

    System.out.println(line);

}

如果您仍想將空白行添加到列表中但不顯示它們,則只需移動條件:


words.add(line);

if(!line.trim().isEmpty())

    System.out.println(line);


查看完整回答
反對 回復 2021-05-26
?
汪汪一只貓

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

ArrayList<String> words = new ArrayList<>();

BufferedReader reader = null;

try {

    reader = new BufferedReader(new FileReader(srcFile));

    String line;

    while ((line = reader.readLine()) != null) {

        line = line.trim(); // remove leading and trailing whitespace

        if (!line.isEmpty() && !line.equals("")) {


            words.add(line);

            System.out.println(line);

        }

    }


查看完整回答
反對 回復 2021-05-26
?
慕神8447489

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

使用System.out.print。請注意,該文件在每一行的末尾包含一個換行符。

如果使用記事本創(chuàng)建了srcFile,請嘗試首先刪除回車符char System.out.print(line.replaceAll("\\r",""))


查看完整回答
反對 回復 2021-05-26
  • 3 回答
  • 0 關注
  • 244 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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