473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Need java help on reading intger elements from file to array list

needhelp123
Hi all,

any body could help in reading integer values from .txt to array list and after transferring the dates from array list to another .txt file

there should be two files....
May 21 '07 #1
29 2728
prometheuzz
197 Expert 100+
Hi all,

any body could help in reading integer values from .txt to array list and after transferring the dates from array list to another .txt file

there should be two files....

Sure, with what part of the assignment are you having trouble with?
May 21 '07 #2
nomad
664 Expert 512MB
Hi all,

any body could help in reading integer values from .txt to array list and after transferring the dates from array list to another .txt file

there should be two files....
Question you need to ask yourself
How do you want to retreive your text files. by a scanner or static.
how do you want to output your t.txt file.
How many data types do you need.
Where do you want to store the output txt files
nomad
May 21 '07 #3
Sure, with what part of the assignment are you having trouble with?

the following information is enought i hope...
* Create a file called Unsorted.txt.
* Store the Unsorted values in this file.
* Read the values from the Unsorted.txt file.
* Sort the values
* Store the sorted values in new file. Name it as Sorted.txt

Implement this only for the following algorithms.

Bubble sort
May 21 '07 #4
Question you need to ask yourself
How do you want to retreive your text files. by a scanner or static.
how do you want to output your t.txt file.
How many data types do you need.
Where do you want to store the output txt files
nomad
I hope following information is enough....

* Create a file called Unsorted.txt.
* Store the Unsorted values in this file.
* Read the values from the Unsorted.txt file.
* Sort the values
* Store the sorted values in new file. Name it as Sorted.txt

Implement this only for the following algorithms.

Bubble sort
May 21 '07 #5
nomad
664 Expert 512MB
I hope following information is enough....

* Create a file called Unsorted.txt.
* Store the Unsorted values in this file.
* Read the values from the Unsorted.txt file.
* Sort the values
* Store the sorted values in new file. Name it as Sorted.txt

Implement this only for the following algorithms.

Bubble sort
Have you read how to I/O files yet and do you know how to create a Arraylist?

nomad
May 21 '07 #6
prometheuzz
197 Expert 100+
the following information is enought i hope...
* Create a file called Unsorted.txt.
* Store the Unsorted values in this file.
* Read the values from the Unsorted.txt file.
* Sort the values
* Store the sorted values in new file. Name it as Sorted.txt

Implement this only for the following algorithms.

Bubble sort
What I meant to say with my post is this: if you don't have any idea where (or how) to start coding *something*, then I cannot help you and you should either hire a private tutor or have a talk with your teacher (I don't mean to put you down!).

But, if you have coded something up and you're getting compiler/runtime errors you don't understand what they mean: post your code AND errors here and explain what it is you're having a hard time with: I'll try to help you.

Good luck.
May 21 '07 #7
nomad
664 Expert 512MB
I hope following information is enough....

* Create a file called Unsorted.txt.
* Store the Unsorted values in this file.
* Read the values from the Unsorted.txt file.
* Sort the values
* Store the sorted values in new file. Name it as Sorted.txt

Implement this only for the following algorithms.

Bubble sort
like prometheuzz we can not help you without see some form of coding.
I'm also new to Java and I willing to help you learn Java from an entry level view points

good luck
May 21 '07 #8
Have you read how to I/O files yet and do you know how to create a Arraylist?

nomad
i know all the things....
to read and create array list
and even i have the program tooo

i need a code where i can transfer data from text to array list....
i am not aware of this little bit...

if i kno this so i can implement the rest...
May 21 '07 #9
What I meant to say with my post is this: if you don't have any idea where (or how) to start coding *something*, then I cannot help you and you should either hire a private tutor or have a talk with your teacher (I don't mean to put you down!).

But, if you have coded something up and you're getting compiler/runtime errors you don't understand what they mean: post your code AND errors here and explain what it is you're having a hard time with: I'll try to help you.

Good luck.

hi prometheuzz
thanks for your concern... i have the program code just i need to know about how to transfer integer data from text file to array list...
May 21 '07 #10
nomad
664 Expert 512MB
i know all the things....
to read and create array list
and even i have the program tooo

i need a code where i can transfer data from text to array list....
i am not aware of this little bit...

if i kno this so i can implement the rest...
if that is the case then you need to use the get()method and set() methods for your data types.

nomad
May 21 '07 #11
prometheuzz
197 Expert 100+
hi prometheuzz
thanks for your concern... i have the program code just i need to know about how to transfer integer data from text file to array list...

Have a look at Sun's I/O tutorial:
http://java.sun.com/docs/books/tutorial/essential/io/scanning.html
May 21 '07 #12
if that is the case then you need to use the get()method and set() methods for your data types.

nomad
this is my java program


Expand|Select|Wrap|Line Numbers
  1.  public class BubbleSort { 
  2.  
  3. int[] bsArrays = new int[5];
  4. int i; //indexing for array(outer loop counter)
  5. int j; //indexing for array*(inner loop counter)
  6.  
  7.  
  8. /**
  9. * Adds element into an array
  10. * sorts the array and print final value...
  11. */
  12. private void setBubblesort() {
  13.  
  14. // Insert elements into an array
  15. bsArrays[0] = 20;
  16. bsArrays[1] = 10;
  17. bsArrays[2] = 50;
  18. bsArrays[3] = 100;
  19. bsArrays[4] = 05;
  20.  
  21. int temp = 0; //variable to store value during manipulation
  22.  
  23. System.out.println("Bubble Sort");
  24. System.out.println(" ");
  25. System.out.println(" ");
  26. System.out.println("Data before Soring ");
  27. System.out.println("**************** ");
  28. for (int val = 0; val < 5; val ++) {
  29. System.out.println("Value at index" + val + " = " + bsArrays[val]); 
  30. }
  31.  
  32. //swaping an elemens
  33. for (i = 0; i < 4; i++ ) {
  34.      for (j = i + 1; j < 5; j ++) {
  35.      if (bsArrays[i] > bsArrays[j]) {
  36.      temp = bsArrays [ i ];
  37.      bsArrays[i] = bsArrays[j];
  38.      bsArrays[j] = temp;
  39.      }
  40. }
  41. }
  42.  
  43. //output: final sorted elements in ana array
  44. System.out.println(" ");
  45. System.out.println(" ");
  46. System.out.println(" After Sorting " );
  47. System.out.println(" **************** ");
  48. for (int fval = 0; fval < 5; fval ++) {
  49. System.out.println("Value at index" + fval + " = " + 
  50. bsArrays[fval]);
  51. }
  52. }
  53.  
  54. /**
  55. * The main method illustrates the use of a Bubble sort
  56. * for small array
  57. */
  58. public static void main(String str[]) {
  59. BubbleSort acc = new BubbleSort();
  60. acc.setBubblesort();
  61. }
  62. }
  63.  
here i have inserted elements directly in the program.. in spite of that i need to get those elements from text file what i mentioned before...
May 21 '07 #13
Have a look at Sun's I/O tutorial:
http://java.sun.com/docs/books/tutorial/essential/io/scanning.html

thank you...
it might help in implenting code if my TL... sujst to use scanner
May 21 '07 #14
prometheuzz
197 Expert 100+
thank you...
it might help in implenting code if my TL... sujst to use scanner
You can or can't use the Scanner class?

Anyway, Scanner examples can be found in the tutorial I posted, and here's an example of how to do it without the Scanner class:
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) throws IOException {
  5.         BufferedReader buffer = 
  6.             new BufferedReader(new FileReader("Main.java"));
  7.         String lineOfText;
  8.         while((lineOfText = buffer.readLine()) != null) {
  9.             System.out.println("> "+lineOfText);
  10.         }
  11.         buffer.close();
  12.     }
  13. }
Have a look at the java.lang.Integer class how to parse a String to a numerical value.

Good luck.
May 21 '07 #15
nomad
664 Expert 512MB
You can or can't use the Scanner class?

Anyway, Scanner examples can be found in the tutorial I posted, and here's an example of how to do it without the Scanner class:
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) throws IOException {
  5.         BufferedReader buffer = 
  6.             new BufferedReader(new FileReader("Main.java"));
  7.         String lineOfText;
  8.         while((lineOfText = buffer.readLine()) != null) {
  9.             System.out.println("> "+lineOfText);
  10.         }
  11.         buffer.close();
  12.     }
  13. }
Have a look at the java.lang.Integer class how to parse a String to a numerical value.

Good luck.
clue read() method
nomad
May 21 '07 #16
clue read() method
nomad

s by using parseint

even i kno this concept but but what i need is.... how you will put this into an array
May 21 '07 #17
prometheuzz
197 Expert 100+
clue read() method
nomad
I would't do that: read() only return single characters. How will you read a numerical value which is larger than 9?
May 21 '07 #18
prometheuzz
197 Expert 100+
s by using parseint
...
Yes, that is correct.


...
even i kno this concept but but what i need is.... how you will put this into an array
You needed to use an ArrayList and not an array, right?
Well then, create an instance of an ArrayList and use it's add methof to add Integers to it. That's all there is to it!
; )
May 21 '07 #19
nomad
664 Expert 512MB
I would't do that: read() only return single characters. How will you read a numerical value which is larger than 9?
so this would not work
This folowing statement use a while loo to read the data file in a FileInputStream object. called largerfile:

int newByte = 0;
while (newByte != -1) {
newByte =largerfile.read();
System.out.print(newByte + " ");
}

nomad
May 21 '07 #20
Yes, that is correct.




You needed to use an ArrayList and not an array, right?
Well then, create an instance of an ArrayList and use it's add methof to add Integers to it. That's all there is to it!
; )
can u please give example for this....
May 21 '07 #21
JosAH
11,448 Expert 8TB
so this would not work
This folowing statement use a while loo to read the data file in a FileInputStream object. called largerfile:

int newByte = 0;
while (newByte != -1) {
newByte =largerfile.read();
System.out.print(newByte + " ");
}

nomad
No insult intended but you'd better leave this thread to Prometheuzz; he can
handle this fine. He doesn't need your or my intervening remarks here. If you
want to know anything about stream IO feel free to start your own thread about
it and I'll read (and possibly answer) your question too. Prometheuzz is right
on target with this thread; read all about it and feel free to post corrections.

kind regards,

Jos
May 21 '07 #22
can u please give example for this....

can you plese give exAMPLE FOR THIS PRO
May 21 '07 #23
prometheuzz
197 Expert 100+
can you plese give exAMPLE FOR THIS PRO
Like I said: I don't know exactly what it is you need help with, and begging for code isn't helping you either.

You had better show me (or us) that you put some effort and research in what I have suggested to you because I pretty much told you what to do in order to finish this assignment.

If there is something not clear to you, then you need to be specific and tell me (us) what it is you don't understand.


Edit: I'll check up on this thread tomorrow morning because it's way passed my bed time (says my girlfriend).
May 21 '07 #24
Like I said: I don't know exactly what it is you need help with, and begging for code isn't helping you either.

You had better show me (or us) that you put some effort and research in what I have suggested to you because I pretty much told you what to do in order to finish this assignment.

If there is something not clear to you, then you need to be specific and tell me (us) what it is you don't understand.


Edit: I'll check up on this thread tomorrow morning because it's way passed my bed time (says my girlfriend).
ok dude...
i need help that
i need a coding help to transfer those data to array element....
May 22 '07 #25
r035198x
13,262 8TB
ok dude...
i need help that
i need a coding help to transfer those data to array element....
Follow the advice that has been given already. If you get stuck with it, no problem. Just post the code that you will have written and see what happens.
May 22 '07 #26
Follow the advice that has been given already. If you get stuck with it, no problem. Just post the code that you will have written and see what happens.
[/quote]


thank you people helping in that mean procedure,,,,,,,,,,,,
i got a code
May 22 '07 #27
prometheuzz
197 Expert 100+
thank you people helping in that mean procedure,,,,,,,,,,,,
i got a code
What are you tryinh to say with: mean procedure? Do you feel you are treated badly?
And what do you mean by: i got a code?
May 22 '07 #28
JosAH
11,448 Expert 8TB
What are you tryinh to say with: mean procedure? Do you feel you are treated badly?
And what do you mean by: i got a code?
My guess is that the OP managed to scrape a non-understood snippet of code
from the internet somewhere which (sort of) compiles and (sort of) seems to do
what the OP wants it to do. Programming is a mean business indeed ;-)

Confused? Watch out for the next episode for "Teh WAnTeD CodeZ!!!eleven11!"

kind regards,

Jos
May 22 '07 #29
What are you tryinh to say with: mean procedure? Do you feel you are treated badly?
And what do you mean by: i got a code?

no i am not...

just i said u that.. i have worked on that... and i got that concept....

of data transfer from file to array list..

using bufferreader, and bufferwriter... for input and out put...

using fileinput stream...
thank you prom.. for helping me in this
May 22 '07 #30

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jason | last post by:
Could anyone spare some time and try to help me out. I've got a .txt data file with a name, pin, balance seperated by commas. I am opening the file and using Split to split it between the ,'s I...
7
by: greenflame | last post by:
I am trying to reorder elements of a list and I am stuck as to what might be the best way to approach this. I have a (main) list of elements and another (ordering) list (which is may shorter, but...
4
by: Fazana | last post by:
I need help for reading a text file into in my java program. The file contains this information: ID# Student’s Answers --------------------------- 236499 TFTFTFTFFFFTFTFFFTF 643828...
3
by: Ant | last post by:
Hi, I'm using an array list as the collection for my indexer (_alPeople). When i try to set _alpeople to a value at a certain index, I get an error. I can't simply add the value as it needs to be...
8
by: bahoo | last post by:
Hi, I have a text file containing a single line of text, such as 0024 How should I read it into a "list"? I tried this, but the "join" did not work as expected. Any suggestions?
6
by: Lisa | last post by:
I am reading in data from a text file. I want to enter each value on the line into a list and retain the order of the elements. The number of elements and spacing between them varies, but a...
4
by: jla1357 | last post by:
In my program I need to read in a file, search for 100 unique words, and count how many times a found word has been found all by using an array. This is what I have so far, but when the file is found...
5
by: Justin | last post by:
Here's my XML: <?xml version="1.0" ?> <AppMode Type="Network"> <CurrentFolder Path="c:\tabs"> <Tabs> <FilePath>tabs\Justin.tab</FilePath> <FilePath>tabs\Julie.tab</FilePath> *****There could...
4
by: zcabeli | last post by:
Hi, i'd like to have an easy way of doing IO operation in files : my main 2 tasks are : 1. reading line from file. for this i've created the following function : sub read_line { my...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.