input-output

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 711 Views - Last Post: 27 March 2011 - 06:46 PM Rate Topic: -----

#1 javabeginner18  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 16
  • Joined: 04-March 11

input-output

Posted 27 March 2011 - 09:20 AM

firstly i read a txt and i wanna this copy a array in java .how can i do this?
  	File file = new File("input.txt");
		        StringBuffer contents = new StringBuffer();
		        BufferedReader reader = null;
		        
		        {
		   
		          try {
		             reader = new BufferedReader(new FileReader("input.txt"));
		              String text = null;
		    
		              // repeat until all lines is read
		               while ((text = reader.readLine()) != null) {
		                   contents.append(text).append(System.getProperty("line.separator"));
		              }


Is This A Good Question/Topic? 0
  • +

Replies To: input-output

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: input-output

Posted 27 March 2011 - 09:29 AM

Use the split() method of the String class.
Was This Post Helpful? 0
  • +
  • -

#3 javabeginner18  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 16
  • Joined: 04-March 11

Re: input-output

Posted 27 March 2011 - 09:50 AM

not enough your help
Was This Post Helpful? -3
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: input-output

Posted 27 March 2011 - 11:08 AM

String[] line = contents.toString().split(System.getProperty("line.separator"));
Was This Post Helpful? 2
  • +
  • -

#5 javabeginner18  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 16
  • Joined: 04-March 11

Re: input-output

Posted 27 March 2011 - 03:05 PM

i read text but i wanna it in two dimensional array . exp: array[][] .how i can do it?

File file = new File("input.txt");
			StringBuffer contents = new StringBuffer();
			BufferedReader reader = null;
			 
			try {
			reader = new BufferedReader(new FileReader(file));
			String text = null;
			 
			// repeat until all lines is read
			while ((text = reader.readLine()) != null) {contents.append(text).append(System.getProperty("line.separator"));
			}
			} catch (FileNotFoundException e) {
			e.printStackTrace();
			} catch (IOException e) {
			e.printStackTrace();
			} finally {
			try {
			if (reader != null) {
			reader.close();
			}
			} catch (IOException e) {
			e.printStackTrace();
			}
			}
			 
			// show file contents here
			System.out.println(contents.toString());
			

Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: input-output

Posted 27 March 2011 - 03:07 PM

View Postjavabeginner18, on 27 March 2011 - 05:05 PM, said:

i read text but i wanna it in two dimensional array . exp: array[][] .how i can do it?

And what are rows and columns in your 2 dimensional array ?
Was This Post Helpful? 1
  • +
  • -

#7 javabeginner18  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 16
  • Joined: 04-March 11

Re: input-output

Posted 27 March 2011 - 03:11 PM

View Postpbl, on 27 March 2011 - 03:07 PM, said:

View Postjavabeginner18, on 27 March 2011 - 05:05 PM, said:

i read text but i wanna it in two dimensional array . exp: array[][] .how i can do it?

And what are rows and columns in your 2 dimensional array ?

[24][57] and iuse this my text i use it for a game but before that iwanna create a aray for this txt
#########################################################
#    ##		    ##		      ##    ##   	#           
# ##### ##### ##### ## ######## ## ##### ## ## ## ## ## #
# ##### ##### ##### ## ######## ## ##### ## ## ## ## ## #
#          ##       ##          ## ##       ##    ##    #
# ##### ##### ##### ## ## ## ## ## ##### ## ######## ####
# ##### ##### ##### ## ## ## ## ## ##### ## ######## ####
#    ## ##                      ##          ##    ##    #
# ######## ## ##### ##### ##### ## ##### ## ## ## ##### #
# ######## ## ##### ##### ##### ## ##### ## ## ## ##### #
#                ##             ##       ##    ##       #
#####A#### ## ##### ##### ##### ##### ##### ## ## ## ## #
########## ## ##### ##### ##### ##### ##### ## ## ## ## #
# ## ##                ## ##                ##    ##    #
# ## ## ## ## ######## ## ## ## ######## ######## ## ## #
# ## ## ## ## ######## ## ## ## ######## ######## ## ## #
#    ##       ## ##       F#    ##    ##                #
# ## ## ## ##### ## ## ########### ##### ######## #######
# ## ## ## ##### ## ## ########### ##### ######## #######
#       ##       ## ##    ##    ##    ## ##       ##    #
# ##### ## ######## ## ## ##### ## ## ## ## ## ##### ## #
# w#### ## ######## ## ## ##### ## ## ## ## ## ##### ## #
#          ##                         ##    ##          #
#########################################################

This post has been edited by javabeginner18: 27 March 2011 - 03:12 PM

Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: input-output

Posted 27 March 2011 - 03:13 PM

View Postjavabeginner18, on 27 March 2011 - 05:11 PM, said:

View Postpbl, on 27 March 2011 - 03:07 PM, said:

View Postjavabeginner18, on 27 March 2011 - 05:05 PM, said:

i read text but i wanna it in two dimensional array . exp: array[][] .how i can do it?

And what are rows and columns in your 2 dimensional array ?

[24][57] and iuse this my text i use it for a game but before that iwanna create a aray for this txt
#########################################################
#    ##		    ##		      ##    ##   	#           
# ##### ##### ##### ## ######## ## ##### ## ## ## ## ## #
# ##### ##### ##### ## ######## ## ##### ## ## ## ## ## #
#          ##       ##          ## ##       ##    ##    #
# ##### ##### ##### ## ## ## ## ## ##### ## ######## ####
# ##### ##### ##### ## ## ## ## ## ##### ## ######## ####
#    ## ##                      ##          ##    ##    #
# ######## ## ##### ##### ##### ## ##### ## ## ## ##### #
# ######## ## ##### ##### ##### ## ##### ## ## ## ##### #
#                ##             ##       ##    ##       #
#####A#### ## ##### ##### ##### ##### ##### ## ## ## ## #
########## ## ##### ##### ##### ##### ##### ## ## ## ## #
# ## ##                ## ##                ##    ##    #
# ## ## ## ## ######## ## ## ## ######## ######## ## ## #
# ## ## ## ## ######## ## ## ## ######## ######## ## ## #
#    ##       ## ##       F#    ##    ##                #
# ## ## ## ##### ## ## ########### ##### ######## #######
# ## ## ## ##### ## ## ########### ##### ######## #######
#       ##       ## ##    ##    ##    ## ##       ##    #
# ##### ## ######## ## ## ##### ## ## ## ## ## ##### ## #
# w#### ## ######## ## ## ##### ## ## ## ## ## ##### ## #
#          ##                         ##    ##          #
#########################################################

You haven't answered my question
Was This Post Helpful? 1
  • +
  • -

#9 javabeginner18  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 16
  • Joined: 04-March 11

Re: input-output

Posted 27 March 2011 - 03:15 PM

sorry sir my english is bad. just i wanna this: this txt copy an array :)
Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: input-output

Posted 27 March 2011 - 03:24 PM

And what are rows and columns in your 2 dimensional array ?
Was This Post Helpful? 0
  • +
  • -

#11 Manbearpig101  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 62
  • Joined: 17-June 10

Re: input-output

Posted 27 March 2011 - 03:27 PM

This will populate a char[][] array of the given dimensions:

Scanner in = new Scanner(new File("input.txt"));
char[][] array = new char[24][57];
for (int i = 0; i < 24; i++) {
    char[] lineArr = in.nextLine().toCharArray();
    for (int n = 0; n < 57; n++) {
        array[i][n] = lineArr[n];
    }
}


Was This Post Helpful? 1
  • +
  • -

#12 javabeginner18  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 16
  • Joined: 04-March 11

Re: input-output

Posted 27 March 2011 - 03:29 PM

View Postpbl, on 27 March 2011 - 03:24 PM, said:

And what are rows and columns in your 2 dimensional array ?

i dont understand what you say. but rows:24 colums:57.if you ask this
Was This Post Helpful? -1
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: input-output

Posted 27 March 2011 - 03:30 PM

View Postjavabeginner18, on 27 March 2011 - 05:15 PM, said:

sorry sir my english is bad. just i wanna this: this txt copy an array :)

An array of what ? String[][] or char[][]

If String[][] based on letters or word ?
Was This Post Helpful? 0
  • +
  • -

#14 javabeginner18  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 16
  • Joined: 04-March 11

Re: input-output

Posted 27 March 2011 - 03:32 PM

View Postpbl, on 27 March 2011 - 03:30 PM, said:

View Postjavabeginner18, on 27 March 2011 - 05:15 PM, said:

sorry sir my english is bad. just i wanna this: this txt copy an array :)

An array of what ? String[][] or char[][]

If String[][] based on letters or word ?

i am really sorry i wanna use char . because i use "##"
Was This Post Helpful? -1
  • +
  • -

#15 Manbearpig101  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 62
  • Joined: 17-June 10

Re: input-output

Posted 27 March 2011 - 03:33 PM

View Postjavabeginner18, on 27 March 2011 - 03:32 PM, said:

View Postpbl, on 27 March 2011 - 03:30 PM, said:

View Postjavabeginner18, on 27 March 2011 - 05:15 PM, said:

sorry sir my english is bad. just i wanna this: this txt copy an array :)

An array of what ? String[][] or char[][]

If String[][] based on letters or word ?

i am really sorry i wanna use char . because i use "##"


Look at the code I put above >.<
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2