0

From third party daily reports i will be getting a similar kind of csv file as shown below

07-Jan-2016
It is better to lead from behind and to put others in front, especially when you celebrate victory when nice things occur. You take the front line when there is danger. Then people will appreciate your leadership.

The main thing that you have to remember on this journey is, just be nice to everyone and always smile.

My requirement is that i need to put each paragraph (A line after space) each quote for above reference in a separate StringBuffer

My question how can i check for empty line ??

I tried with

if(line.contains("            "))
{
System.out.println("hjjjjjjjjjjjjjjjjk");
}

But the above is causing issue where ever there is a space

I am reading the csv file as shown below

 String csvFile = "ip/ASRER070116.csv";
  BufferedReader br = null;
  String line = "";
  try {
   br = new BufferedReader(new FileReader(csvFile));
   while ((line = br.readLine()) != null) {
    if (line.startsWith(",")) {
     line = line.replaceFirst(",", "");
    }
    System.out.println(line);
   }
  } 

Could you please tell me how to resolve this ??

2
  • You can check if all the chars in the line (if any) are spaces and/or carriage returns Commented Jan 7, 2016 at 14:27
  • Possible duplicate of How to check empty spaces in java Commented Jan 7, 2016 at 14:30

3 Answers 3

1
if (line != null && (line.trim().equals("") || line.trim().equals("\n"))){
   System.out.println("this is empty line");
}
Sign up to request clarification or add additional context in comments.

1 Comment

@Preethi Jain pl accept the answer if it really worked.
1

I would suggest you use trim() on the read line and then check if line.length == 0

Comments

0

You can use StringUtils.isBlank method from Apache Commons Lang

public static boolean isBlank(CharSequence cs)

Checks if a CharSequence is whitespace, empty ("") or null.

 StringUtils.isBlank(null)      = true
 StringUtils.isBlank("")        = true
 StringUtils.isBlank(" ")       = true
 StringUtils.isBlank("bob")     = false
 StringUtils.isBlank("  bob  ") = false

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.