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"));
}
19 Replies - 537 Views - Last Post: 27 March 2011 - 06:46 PM
#1
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?
Replies To: input-output
#4
Re: input-output
Posted 27 March 2011 - 11:08 AM
String[] line = contents.toString().split(System.getProperty("line.separator"));
#5
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());
#6
Re: input-output
Posted 27 March 2011 - 03:07 PM
#7
Re: input-output
Posted 27 March 2011 - 03:11 PM
pbl, on 27 March 2011 - 03:07 PM, said:
[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
#8
Re: input-output
Posted 27 March 2011 - 03:13 PM
javabeginner18, on 27 March 2011 - 05:11 PM, said:
pbl, on 27 March 2011 - 03:07 PM, said:
[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
#9
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
#10
Re: input-output
Posted 27 March 2011 - 03:24 PM
And what are rows and columns in your 2 dimensional array ?
#11
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];
}
}
#12
Re: input-output
Posted 27 March 2011 - 03:29 PM
#13
Re: input-output
Posted 27 March 2011 - 03:30 PM
#14
Re: input-output
Posted 27 March 2011 - 03:32 PM
#15
|
|

New Topic/Question
Reply




MultiQuote



|