How to split the new line character("\n") in string in JAVA

Hi,

   I have a string where there is a new line character ("\n") and i want to split the new line character .
Example of string :
   afasdfasdf
sfasdfasdffgsdgsg
dfhdgg
ghjh

After splitint the above string with str.split("\n");
i'm not able to get the splited part of the string pls suggest me how to split a string according to new line character

Thanx
LVL 1
mohan21_kumarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

murugesandinsC C++ Shell script AIX CYGWIN_NT HP-UX Linux MINGW SunOSCommented:
public class Dinesh_P_V
{
      public static void main(String ars[])
      {
            String s="Dinesh\n_\nP\n_\nV";
            System.out.println("Before Split:");
            System.out.println(s);
            String arr[]=s.split("\n");
            System.out.println("After Split:");
            for(int i=0;i<arr.length;i++)
            System.out.println(arr[i]);
      }
}

HTH
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mohankumarbangaloreCommented:
the above code works but i want to check it for the file and split the file into no of files according to tne paragraph
0
murugesandinsC C++ Shell script AIX CYGWIN_NT HP-UX Linux MINGW SunOSCommented:
http://www.javacoffeebreak.com/java103/java103.html

Here you can have a view on file handling in java.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.