Reading s file and saving a the dta to an array

Hi,
I have a txt file that is contained of text and numbersso this is the format :
hdfsgfjsgfjsfg
kshfkwhfl
kshfakh
kahflak
Xunit , YUNIT
1,2
2,3
5,4
So I want to read this file and save the numbers to two arrays, here is my code, and it gives error on Ch[i] = result[1]; it also say array out of bound and it gives me the watrning that ReadDile.java overrides a depricated API. hELP:
import java.net.*;
import java.io.*;
import java.util.*;
import java.lang.*;
public class ReadFile {
public static void main(String[] args) throws IOException {
/*Open the file and Read the file
     File inputFile = new File("wfmdata.txt");
     FileReader in = new FileReader(inputFile); */
     FileInputStream fis = new FileInputStream("wfmdata.txt");
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
     String c;
     String[] T = new String[10012];
     String[] CH = new String[10012];
int i=0;
for(;;)
/*Read one line and store it in variable c */
c = dis.readLine();
//if a null line return
if(c != null)
if( (c == "XUNIT , YUNIT"))
continue;
String[] result = c.toString().split(",");
T[i] = result[1];
CH[i] = result [1];
System.out.println( T[i] + "," + "CH" + result.length);
i++;
     }else
dis.close();
how would I change the code to get rid of the errors!
there are 10000 lines of numbers(data).
Sanaz,

If you are only trying to read in integers i would recommend a different approach. Try using the scanner class. It's new to 1.5 It basically splits up everything in the data source into tokens based on where there is white space. what might interest you is that it has methods to just retrieve primitive types ints, doubles etc.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html
you might try something like this. It will ignore strings and just handle integers, based on the format you have given.
import java.util.Scanner;
import java.io.*;
public class ReadFile
    public static void readFile() throws FileNotFoundException
        Scanner sc = new Scanner(new FileReader("C:\\YourFile.txt")); // set the source of the data and create a scanner object to tokenize the data
        int[] xUnit = new int[10012]; // initialise the integer arrays
        int[] yUnit = new int[10012];
        while (sc.hasNextInt() == false) // checks to see if the next "token" read by the scanner is an integer
            sc.next(); // moves onto the next token until an int is found.
        for (int count = 0; count < xUnit.length; count ++)  // goes through the array until it hits the end
            xUnit[count] = sc.nextInt(); //assigns the int to the array
            sc.next(); // skips the comma
            yUnit[count] = sc.nextInt(); //assigns the next int to the other array
        for (int count = 0; count < xUnit.length; count ++)
            System.out.println( xUnit[count] + "," + yUnit[count]); //prints out all the data read in
}Bear in mind my java experience is fairly limited, so this may not be what you're after.

Similar Messages

  • Program to read html file and to open the links in that html file

    program to read html file and to open the links in that html file..
    ex:- to read automatically all next links in the html file and save it hard disk

    Start here;
    http://java.sun.com/products/jfc/tsc/articles/bookmarks/
    It gives you all of the information you need to parse the HTML file using the HTMLEditorKit that is a part of the Java SDK.
    Once you get the links from the file, then you can think about connecting to each.

  • Reading text file and display in the selectOnechoice list item In ADF.

    Hi,
    I have a requirement to read the text field which have list of strings and that string display in the SelectOneChoice List item component on page load.
    I am using Jdeveloper 11.1.2.3 version.
    Any suggestion will highly appreciated..
    Thanks in advance.
    Regards

    Hi,
    Google will produce you with hints on how to read content of a file from Java (ideally the file uses some delimiter). Then in a managed bean, you read the file and save its content in a list of SelectItem. So your managed bean should have the following property and setter/getter pairs
    ArrayList<SelectItem> listFromFile = new ArrayList<SelectItem>();
    public void setListFromFile(ArrayList l){ //you don't need this }
    public ArrayList<SelectItem> getListFromFile(){
       //read file content and iterate over the file list entries
      for(i=0, i < fileContent.length, ++i){
         SelectItem si = new SelectItem();
         si.setValue(... the value to update the list of value with ...);
         si.setLabel("... the label to show in the list ...");
         listFromFile.add(si);
      return listFromFile;
    }The af:selectOneChoice component should look as follows
    <af:selectOneChoice id=".." value="...attribute to update with selection ..." ...>
       <f:selectItems value="#{managedBean.listFromFile}"/>
    </af:selectOneChoice>Frank

  • How can I dynamicall​y read a file and show/plot the data in the GUI?

    Hi, everyone,
    I hope to implement a VI with the following function:
    Usually, when we "read a file" in VI and then show the data in the Waveform Chart or other display GUI, the VI will first read and record all of the data from the file and then show them simultaneously. Now, I want to implement a VI, which could read  the data from a file and display it in a time series. That is, I can define a "sampling rate" or "reading rate", like 100 data points / second,  then the data points could be correspondingly shown in Waveform Chart one by one as the time moves on. The key purpose is to simulate a real-time data collection module using an existing file.
    I don't know how to implement this function. Any suggestion and solution are really appreciated.
    Thanks.
    Zhanpeng

    Heres the same effect, just a different approach :
    The code in the red box was used to create data that you would be getting from a file.
    What you could do is (shown above) :
    - Read all of the data
    - Index only one value at a time, and set the 'sampling rate' using a wait in a while loop.
    - Build an array using this value, which will simulate collecting data in real time.
    - I used an array of the iterations as X-values, because they coincidentally correspond to # seconds in my example
    - I then bundled the time array (xvalues) with the values from your file (yvalues)
    - Send that bundle to an XY graph
    That should work, though you could implement some different logic for different sampling rates.
    Let me know if you need a hand with that.
    Message Edited by Cory K on 02-26-2009 11:36 AM
    Cory K
    Attachments:
    graph from file.PNG ‏10 KB

  • Read text file and insert into MySQL

    Dears,
    I need to read text file and then insert the data in the correct column in the MySQL database
    example
    I have the following text file:
    field1=1234 field2=56789 field3=444555
    field1=1333 field2=2222 field3=333555
    and so on and so forth ,,note that all rows are identical and just the filed value is changed(there is a dilemeter between fields)
    how can I read field1,field2 and field3 from text file and insert them in the correct table and column in the database.....
    any help?????
    thanks for your cooperation
    Best Regars

    Sure.
    Which part don't you understand?
    1. Reading a text file
    2. Parsing the text file contents.
    3. Relational databases and SQL.
    4. How to create a database.
    5. How to connect to a database in Java.
    6. How to insert records into the database in Java.
    7. How to map Java objects to records in a database.
    This is a pretty nice list. Solve complex problems by breaking them into smaller ones.
    %

  • I am getting messages that I can't download and read .pdf files since I have the wrong Adobe reader. I know about their security disasters of course, but I downloaded the latest version of Adobe Reader from the Adobe web site and I have other ,pdf file re

    I am getting messages that I can't download and read .pdf files since I have the wrong Adobe reader. I know about their security disasters of course, but I downloaded the latest version of Adobe Reader from the Adobe web site and I have other ,pdf file readers as well, and for some reason they won't work either. I have 5 computers running top end processors and RAM. By this I mean I have one, this one which I am using that has an AMD Phenom Black 3.2 Quad-core with 8 GBs of Corsair top DDR2 RAM, my other two AMD have either an Athlon II triple core with 4 GBs of DDR2 Corsair RAM, one with the Phenom X4 965 3.4 GHz Quad-core with 8 GBs of their best DDR2 RAM, and two Intels with the i7 920 Processors using the triple channel 1366 socket processors and one with 8 GBs of low latency DDR3 RAM and the other with 4 GBs of the same RAM. I am getting the message on this one, which has a fresh install of XP Pro X64 operating system, as do the other 4 as well. I have run Avast Business Pro Anti-virus on this one, which I am getting the message on with a single result which I deleted, and also both Spybot Search and Destroy, which came back clean as well as Malwarebytes Antimalware, which got a lot of tracing cookies now removed, and SuperAntiSpware which also found a few cookies also now deleted. Can you tell me what I need to do to get these files to show as .pdf files rather than as a clean blank page. One other issue is that I wish to know how to turn off my downloads so they are saved and Mozilla will give me the option of returning them instead of me losing them all together as it does now. Thanks for your assistance. If there is another Adobe reader I should download and install, could you provide me with the link to it? I appreciate your assistance here
    == When I download and try to read a .pdf file and when I am asked to turn off all Firefox files and if I do, I lose them since I need to know how to save them without rebooting my computer.

    Brilliant! Problem solved! Thanks so much.

  • I have just load form Pdf file and saved try to sign or type the form,it will not let me?

    Downloaded PDF file and try to type the form or sign the form, it it will not let me?

    From: Pat Willener [email protected]
    Sent: 11 December 2012 02:36
    To: chandabajaj
    Subject: I have just load form Pdf file and saved try to sign or type the form,it will not let me?
    Re: I have just load form Pdf file and saved try to sign or type the form,it will not let me?
    created by Pat Willener <http://forums.adobe.com/people/pwillener>  in Adobe Reader - View the full discussion <http://forums.adobe.com/message/4911163#4911163

  • How to read the data file and write into the same file without a temp table

    Hi,
    I have a requirement as below:
    We are running lockbox process for several business, but for a few businesses we have requirement where in we receive a flat file in different format other than how the transmission format is defined.
    This is a 10.7 to 11.10 migration. In 10.7 the users are using a custom table into which they are first loading the raw data and writing a pl/sql validation on that and loading it into a new flat file and then running the lockbox process.
    But in 11.10 we want to restrict using temp table how can we achieve this.
    Can we read the file first and then do validations accordingly and then write to the same file and process the lockbox.
    Any inputs are highly appreciated.
    Thanks & Regards,
    Lakshmi Kalyan Vara Prasad.

    Hello Gurus,
    Let me tell you about my requirement clearly with an example.
    Problem:
    i am receiving a dat file from bank in below format
    105A371273020563007 07030415509174REF3178503 001367423860020015E129045
    in this detail 1 record starting from 38th character to next 15 characters is merchant reference number
    REF3178503 --- REF denotes it as Sales Order
    ACC denotes it as Customer No
    INV denotes it as Transaction Number
    based on this 15 characters......my validation comes.
    If i see REF i need to pick that complete record and then fill that record with the SO details as per my system and then submit the file for lockbox processing.
    In 10.7 they created a temporary table into which they are loading the data using a control file....once the data is loaded into the temporary table then they are doing a validation and updating the record exactly as required and then creating one another file and then submitting the file for lockbox processing.
    Where as in 11.10 they want to bypass these temporary tables and writing it into a different file.
    Can this be handled by writing a pl/sql procedure ??
    My findings:
    May be i am wrong.......but i think .......if we first get the data into ar_payments_interface_all table and then do the validations and then complete the lockbox process may help.
    Any suggestions from Oracle GURUS is highly appreciated.
    Thanks & Regards,
    Lakshmi Kalyan Vara Prasad.

  • I HATE my new MACBOOK PRO, it will not let me open any PDF files and I downloaded the ADOBE READER three freaking times and it keeps saying that all the files are corrupt. I would rather have my 2008 Dell at this point. what is wrong with this thing

    I HATE my new MACBOOK PRO, it will not let me open any PDF files and I downloaded the ADOBE READER three freaking times and it keeps saying that all the files are corrupt or damaged. I would rather have my 2008 Dell at this point. what is wrong with this thing

    Perhaps the PDF files are corrupted.
    Hit the command key and spacebar, a blue Spotlight in the upper right hand corner appears, now type Preview and press return on the Preview program.
    Now you can try opening the PDF's from the file menu and see what's going on.
    If they are corrupted, perhaps they are trojans from your Windows PC or gotten from a bad location online.
    Download the free ClamXav and run a scan on the possibly infected folder.

  • After reinstalling CS6 the bridge photo downloader isn't able to read raw files and fails to convert the raw files to DNG. Previously downloaded raw files, now DNG, open up successfully in Camera Raw 7. How do I get the photo downloader to read and conver

    After reinstalling CS6 the bridge photo downloader isn't able to read raw files and fails to convert the raw files to DNG. Previously downloaded raw files, now DNG, open up successfully in Camera Raw 7. How do I get the photo downloader to read and convert raw files. MacBook Pro with Snow Leopard. No such problem before this reinstallation.

    You should install Camera Raw 4.6.
    Visit this page and follow the instructions carefully:
    PC:    http://www.adobe.com/support/downloads/detail.jsp?ftpID=4040
    Mac:  http://www.adobe.com/support/downloads/detail.jsp?ftpID=4039
    -Noel

  • Reading text file and output (to stdout) a list of the unique words in the

    Hi,
    I have a main method as
    main.java
    package se.tmp;
    public class Main
    public static void main( String[] args )
    WordAnalyzer.parse( args[0] );
    and text file as
    words.txt
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the requirement is like
    I need create this WordAnalyzer class, implement the parse method, and then commit the file. This method takes a single parameter, the filename of the file to parse. The method should read this file and output (to stdout) a list of the unique words in the file along with the number of times each appears in the file.
    Can anyone please help me on this?
    Thanks.

    Where are you having problems?

  • Reading a file and changing one part of the file

    I am trying to read a file and then I want to change the first value on each line. The file I am reading is a .HEADER file. Which is just read in notepad I am just opening this like a txt file. I get no say at all how this file is created originally
    I want to change the value on the first line the a new title plus the ext .dat. The file is below. This stays the same format just with different values.
    ECG000 1 171 26112 9:14:56 23/04/2002
    ECG000 8 43(0) 8 127 79 -24066 0 AED trace
    I want to change the ECG000 to a new value eg Pat1.dat on the first line and Pat1 on the second line. When I read this file in and output to the dos window I get ECG000 0 0 0 and that is it. Any ideas why this is happening and how I can replace the values in the file??
         private void FileExt() throws IOException
              System.out.println("In function");
              BufferedReader br = new BufferedReader(new FileReader("c:\\Projects\\FirstSupport\\ECG000.HEADER"));
              String s;
              Vector data = new Vector();
              ECGFile = new FileWriter("c:\\Projects\\FirstSupport\\ECG.txt",true);
              System.out.println("Reading the file");
              while ((s = br.readLine()) != null)
              data.add(s);
              System.out.println(s);
              System.out.println("Finished");
              String label = s.substring(0, s.indexOf(" "));
              System.out.println(label);
              String newLabel = (label+".dat");
              System.out.println(newLabel);
         }

    I think this is what you're looking for:     private void FileExt() {
              java.util.List data=new ArrayList();
              String s;
              try {
                   BufferedReader br=new BufferedReader(new InputStreamReader(
                        new FileInputStream(new File("ECG000.HEADER"))));
                   while ((s = br.readLine()) != null)  {
                        data.add(s);
                        System.out.println(s);
                   br.close();
              catch (FileNotFoundException fnfe) {
                   System.out.println("Input file not found");
                   return;
              catch (IOException ioe) {
                   ioe.printStackTrace();
                   return;
              ListIterator li=data.listIterator();
              try {
                   PrintWriter ECGFile=new PrintWriter(new FileOutputStream(
                        new File("ECG.txt")));
                   while(li.hasNext()) {
                        s=(String)li.next();
                        if (s.substring(0, 6).equals("ECG000")) {
                             s="Pat1.dat"+s.substring(6, s.length());
                        ECGFile.println(s);
                   ECGFile.close();
              catch (FileNotFoundException fnfe1) {}
         }Mark

  • How to read XML file and update the data in MS CRM 2011?

    Hi Folks,
    Can anyone please help me finding some references to read XML files and push the data to MS CRM 2011 preferably by using a console application.
    Please let me know if any ways of handling it in simple ways.
    Thanks,
    Sri

    HI,
    How to read XML file:
    https://social.msdn.microsoft.com/Forums/en-US/5dd7261b-86c4-4ca8-ba87-95196ef3ba50/need-to-display-xml-file-in-textboxes-edit-the-data-and-save-the-new-xml-file?forum=csharpgeneral
    How to work with CRM:
    ClientCredentials credentials = new ClientCredentials();
    credentials.Windows.ClientCredential = new System.Net.NetworkCredential("USER", "Password", "Domain");
    Uri uri = new Uri("http://server/Organization/XRMServices/2011/Organization.svc");
    OrganizationServiceProxy proxy = new OrganizationServiceProxy(uri, null, credentials, null);
    proxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
    IOrganizationService service = (IOrganizationService)proxy;
    //using "service" you can create, update and retrieve entities.
    More information here about service functions:
    https://msdn.microsoft.com/en-us/library/gg328198.aspx

  • How to synchronize if one servlet read a file and anothe servlet update the

    How to synchronize if one servlet read a file and anothe servlet update the file at a time?

    Create a class that holds the reference to the file and do the whole file manipulation just in that class. than synchronize the read and write methodes. A reference to this file handler class can be stored to the servlet context in one servlet and read out from the servlet context in the other servlet.

  • I tried to download the trial version of elements 10.  I only got the read me files and the organize

    I tried to download the trial version of elements 10.  I only got the read me files and the organizer.

    Please post the PSE query over the following forums and lets discuss it over there.
    http://forums.adobe.com/community/photoshop_elements
    Thanks and regards
    Harshit yadav

Maybe you are looking for

  • Create a new track for SAP E-Commerce 5.0

    Hi all, I have all the SCA files with me for the E-Commerce application. I want to create a track so that I can access it in my NWDS Can anyone help me in creating a track for SAP E-Commerce. How to go about it please let me know SCA Files 1)CUSTCRMP

  • Purchase requistion line item

    Hi, My client  has following business process *pr- pr release- rfq Created with ref to PR(Maintain and price compare),PO with ref to Rfq - Migo - Miro, My issue is that when i create PR for four line item and go for Release in ME54N , I release only

  • PROBLEM IN ACTIVATION OF A CLASS WHICH IS COPIED FROM STD CLASS

    Hi All,          I have a problem in activating a class which is copied from the standard class. std class: CL_GUI_FRONTEND_SERVICES The class has got some protected methods and attributes. here i'm getting following error whenever i try to activate

  • Need help with my SL

    hello ladies and gents, i got a zen sleek and a love it only thing that sucks is the lack of assessories. my question is...is there any way to hook up the sleek to you car audio system with using a cassette adapter or FM transmitter. by the way i do

  • WD ABAP

    Hi, I have to create a WD application where I will have an input field, a submitt button and a textview. The scenario is such that if I put any thing in input field and click submit button, whatever I have written in input field it will be shown in t