Scala: How to remove blank lines when reading text from file

Shiwei Cao

How can I ignore or remove blank lines, when reading from a text file using Scala?

An example is shown below: As you can see, the second line is the extra line.

I. The Period

It was the best of times,

Gustek

try this.

val file = Source.fromFile(args(0)).getLines().filter(!_.isEmpty()).mkString(" ")

It will remove empty lines from list of lines and then concatenate them into one string with space between lines.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to remove blank lines from text file using powershell

From Dev

How to remove blank lines from text file using powershell

From Dev

How can I prevent my program from adding unwanted blank lines when reading and printing from text file - Python3

From Dev

How to remove multiple blank lines from a file?

From Dev

How to remove multiple blank lines from a file?

From Dev

I can't print blank lines when reading values from a text file using awk in a bash script

From Dev

how to remove blank text file from folder?

From Dev

Blank lines when reading CSV file in Java

From Dev

Checking for extraneous blank lines when creating objects from a text file

From Dev

How to remove specific lines from a text file?

From Dev

Reading Lines of Text from a File

From Dev

How to remove blank lines from a file (including tab and spaces)?

From Dev

How to compare strings from seperate lines when reading from a text file

From Dev

How to remove a place holder in a text file with text from another file when multiple lines are present?

From Dev

string segmentation fault when reading lines from text file

From Java

Remove lines from a file corresponding to blank lines of another file

From Dev

Reading text file and skipping blank lines until EOF is reached

From Dev

reading a text with blank lines in Python

From Dev

How to remove blank lines from HTML with HTMLAgilityPack?

From Dev

How to remove blank lines from HTML with HTMLAgilityPack?

From Dev

How to remove more than one space when reading text file

From Dev

Reading groups of lines from a large text file

From Dev

Reading lines from text file to structs C

From Dev

Remove extra blank lines from CMD adb shell, when redirected to file

From Dev

How to remove particular words from lines of a text file?

From Dev

How to remove particular words from lines of a text file?

From Dev

How can I remove all lines not containing `@` from a text file?

From Dev

How to remove duplicate lines from a large text file efficiently?

From Dev

Reading a text file from HDFS in Scala/Spark

Related Related

  1. 1

    How to remove blank lines from text file using powershell

  2. 2

    How to remove blank lines from text file using powershell

  3. 3

    How can I prevent my program from adding unwanted blank lines when reading and printing from text file - Python3

  4. 4

    How to remove multiple blank lines from a file?

  5. 5

    How to remove multiple blank lines from a file?

  6. 6

    I can't print blank lines when reading values from a text file using awk in a bash script

  7. 7

    how to remove blank text file from folder?

  8. 8

    Blank lines when reading CSV file in Java

  9. 9

    Checking for extraneous blank lines when creating objects from a text file

  10. 10

    How to remove specific lines from a text file?

  11. 11

    Reading Lines of Text from a File

  12. 12

    How to remove blank lines from a file (including tab and spaces)?

  13. 13

    How to compare strings from seperate lines when reading from a text file

  14. 14

    How to remove a place holder in a text file with text from another file when multiple lines are present?

  15. 15

    string segmentation fault when reading lines from text file

  16. 16

    Remove lines from a file corresponding to blank lines of another file

  17. 17

    Reading text file and skipping blank lines until EOF is reached

  18. 18

    reading a text with blank lines in Python

  19. 19

    How to remove blank lines from HTML with HTMLAgilityPack?

  20. 20

    How to remove blank lines from HTML with HTMLAgilityPack?

  21. 21

    How to remove more than one space when reading text file

  22. 22

    Reading groups of lines from a large text file

  23. 23

    Reading lines from text file to structs C

  24. 24

    Remove extra blank lines from CMD adb shell, when redirected to file

  25. 25

    How to remove particular words from lines of a text file?

  26. 26

    How to remove particular words from lines of a text file?

  27. 27

    How can I remove all lines not containing `@` from a text file?

  28. 28

    How to remove duplicate lines from a large text file efficiently?

  29. 29

    Reading a text file from HDFS in Scala/Spark

HotTag

Archive