Go Back   Java Programming Forums > Java Standard Edition Programming Help > File I/O & Other I/O Streams


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-03-2010, 05:33 PM
Junior Member
 

Join Date: Jan 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Scottj996 is on a distinguished road
Default Splitting File into Array

Hi,

Basically I have a text file that I want to read line by line (I have this bit working) and write it to an array.

However I want the data from the text file to be split after every character.

For example:

Text file line 1: ABCDEFG
Array: { A, B, C, D, E, F, G}

Could anyone give me any help on this?

Thanks
SJ996



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 03-03-2010, 01:51 AM
copeg's Avatar
Moderator
 
9 Highscores

Join Date: Oct 2009
Posts: 570
Thanks: 7
Thanked 131 Times in 125 Posts
copeg will become famous soon enoughcopeg will become famous soon enough

I'm feeling Sleepy
Default Re: Splitting File into Array

If you split a string on an empty string, it will split that string on characters:
Java Code
		String sb = "ABCDE";
		String[] s = sb.split("");
		for (String st : s ){
			System.out.println(st);
		}
Reply With Quote
  #3 (permalink)  
Old 03-03-2010, 01:56 AM
helloworld922's Avatar
Super Moderator
 

Join Date: Jun 2009
Posts: 1,215
Thanks: 5
Thanked 258 Times in 234 Posts
helloworld922 will become famous soon enoughhelloworld922 will become famous soon enoughhelloworld922 will become famous soon enough
Default Re: Splitting File into Array

You can get a character at a certain position in the string using the charAt() method:

Java Code
String str = "Hello";
str.charAt(1); // 'e'
__________________
ASCII a question .. Get an ANSI

Please surround your code with [highlight=Java]code goes here[/highlight].
Reply With Quote
  #4 (permalink)  
Old 03-03-2010, 03:19 PM
Junior Member
 

Join Date: Jan 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Scottj996 is on a distinguished road
Default Re: Splitting File into Array

Thanks for the replies. this has helped alot.

Does anyone know how to omit the first two lines from the input text file every time? As i do not want these in the array.

Scott
Reply With Quote
  #5 (permalink)  
Old 03-03-2010, 03:48 PM
helloworld922's Avatar
Super Moderator
 

Join Date: Jun 2009
Posts: 1,215
Thanks: 5
Thanked 258 Times in 234 Posts
helloworld922 will become famous soon enoughhelloworld922 will become famous soon enoughhelloworld922 will become famous soon enough
Default Re: Splitting File into Array

Use a "dummy read", ie. read them in but don't do anything with that data.
Java Code
// skip two lines
myReader.nextLine();
myuReader.nextLine();
__________________
ASCII a question .. Get an ANSI

Please surround your code with [highlight=Java]code goes here[/highlight].
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Create new Array from old Array satory Collections and Generics 1 24-02-2010 04:44 PM
Problems with File Reader (Strings and 2D Array Storage) K0209 File I/O & Other I/O Streams 44 12-01-2010 02:48 PM
unable to move xls file(file name has space in between) from input folder to back up raji What's Wrong With My Code? 8 06-01-2010 01:59 PM
Object array to int array? rsala004 Collections and Generics 1 30-10-2009 08:09 AM
Storing an array into an array vluong Collections and Generics 4 22-09-2009 07:14 PM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 01:52 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.