Forums Register Login
split the data
hi guys

i have a test file like raju.txt

naga raju rama raju

using java.util.Scanner we can split like


the code is

public class FileRead1 {

public static void main(String arg[])
File f=new File("test.txt");
Scanner ss=new Scanner(f);

String hh=ss.next();


}catch(Exception e){}

what my idea is how to split the file like 5,8,10 charatcers like and store it in array .

give the idea.

Plese use code tags round quoted code; it makes it easier to read.

You would have to
  • Read the file line by line; each line is returned as a String.
  • (Optional): Append the line to a StringBuilder object, if you wish to split the whole file rather than splitting each line
  • Get the length of the String you wish to split
  • Divide the length by the number of letters you want in each piece
  • Set up an array of appropriate length
  • Use a for loop to go along the String and get substrings.
  • I think that would work for what you are suggesting.
    Please don't post the same question multiple times.
    This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
    RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database

    Reply locked
    This thread has been viewed 728 times.

    All times above are in ranch (not your local) time.
    The current ranch time is
    Jan 19, 2019 21:46:27.