How can I read a line of numbers in a file?

Hello everybody,
I have a ziped.file organized in this way:
number1 number 2 number3 name1, name2, name3
number_of points information_about_number_of_point
number4 number4 number4 number4
number4 number4 number4 number4
number4 number4
number5 number5 number5 number5 number5 number5
number5 number5 number5 number5 number5 number5
number5 number5 number6 number6 number6 number6
number6 number6 number6 number6 number6 number6
number6 number6
My problem is to save number1 number 2 number3 and in number_of points in 3 different variable, and number4 number5 and number 6 in 3 different array. How can I do this?
The beginning of my file is:
10000 3.50000 0.00000 Teff, logg, [M/H]
52790 number of wavelength points
1.000000000000000e+01 1.200000000000000e+01 1.400000000000000e+01 1.600000000000000e+01 (end of3th line)
1.800000000000000e+01 2.000000000000000e+01 2.200000000000000e+01 2.400000000000000e+01 (end of 4th line)
The number 52790 is the same for number4, number 5 and number6.
Number4 are organized in 4 columns, number5 and 6 in 6 coloums and the spacing is always the same.
Could you help me please?Thank you and sorry for my terrible english!

I'm not sure if I understand completely, but basically you just need to read & parse your files.
Use a lexer/parser tool like JavaCC if it's advanced parsing, or if it's something very simple (like assigning variables) then you can just use the String.split() method to break up your file into tokens. See below for examples of the "simple way"...
If you have any questions, don't hesitate to ask!
I need to save my informazioni in this way:
var1=number1
var2=number2
var3=number3If you wish to access these variables in a Java program, you could split up your file into tokens and then place the values in a map (variable/value pairs). I don't know how efficient this is, but it works nicely. You can change this for arrays, objects, etc.. right now it's only set up for ints.
Here's a very simple example with some code. Below is the text file...
my_var = 123
my_age = 16
x_pos  = 2
err=2 //syntax error. must separate tokens with whitespaceTo get your variables from the text file:
Map<String, Integer> map;
//read text file and put it into string
//then use tokenExample to get a Map for that string
map = tokenExample(textfileString); //see below
//and finally assign your variables
int my_var = map.get("my_var");
int my_age = map.get("my_age");
int x_pos  = map.get("x_pos");
The tokenExample(String) method
This method breaks the speified string into tokens, and returns a Map with all of the variable name/value pairs in the string.
  public static Map<String, Integer> tokenExample(String text) {
       //Sets up our tokens.
     final String ASSIGN   = "=";
       final String NUMBER   = "\\d+";
       final String VARIABLE = "[a-zA-Z]([a-zA-Z]|_|[0-9])*";       
       //Map for our variable/value pairs
       Map<String, Integer> variables = new Hashtable<String, Integer>();
       String[] splitText = text.split("\\s+"); //Splits by whitespace
       String varName = null;
       boolean assigning = false;
       //cycles through each token and decides what to do
       for(String value : splitText) {        
         //if it's a variable, we set up it's name for later
         if (value.matches(VARIABLE)) {
          varName = value;
         //if it's an assignment operator, we get ready to assign the variable
         else if (value.matches(ASSIGN)) {
           assigning = true;
         //if it's a number, we put it into our hashmap
         else if (value.matches(NUMBER)) {
              //if there's no problem with the last two tokens
           if (varName!=null & assigning==true) {
             variables.put(varName, Integer.parseInt(value));
             assigning=false; //reset for next time
             varName=null;
         //some sort of syntax error
         else {
           assigning=false;
           varName=null;
           System.err.println("Syntax error: cannot find token "+value);
       }//end loop
       return variables;
  }See also:
http://mindprod.com/jgloss/regex.html
http://java.sun.com/docs/books/tutorial/extra/regex/
http://www.javaregex.com/tutorial.html

Similar Messages

  • How can i remove a line from an ordinary text file?

    It is easy to remove a line from a file by rewriting the file. how can i remove a line without rewriting ? Also, do not use whitespaces to overwrite the line. I expect a perfect line deletion code .....

    gimbal2 wrote:
    hsc71 wrote:
    It's the way you communicate. Try to be carefull with the words you use in your post. It's easy to insult people just by choosing the wrong words. Bold text and capitals is equal to shouting.
    shock. You said "wrong words". I am seriously offended by that!
    Seriously, would you care that I am offended? I really hope not... Say what you want, people will find reasons to take offense one way or the other.Hehe, maybe you're right, but the OP still has no answer.............and in the end that's what he/she is looking for.

  • How can I read a column of numbers saved as .txt and display as a wave?

    Hi Tiano
    LabVIEW General
    Ask:
    Please enter a one-line summary of your question
    Resources
    • Technical Support
    • Development Library
    • Measurement Encyclopedia
    "data/time reading into chart"
    "In the attached file, I am trying to read the first column of data, and the next column is the value on the x-axis I want it plotted at. How do I read two columns of different data? I have looked in the books I have access to and the help within Labview but am still having trouble.
    Thank you,
    Ellie"
    data_set (Plain Text, 3K)
    -posted by Ellie on 9/11/2001
    markwysong on 9/11/2001 answered:
    "Ellie,
    The first thing you need to do is to read your file in as a spreadsheet file. Then, you display it in a chart.
    That sounds simple, but looking at your dataset, there's a few things you should know. First, the "read from spreadsheet VI" is looking for data in columns, like your data set, but columns separated by tabs. Therefore, your data must be saved that way; currently, it doesn't seem that it is. Another thing; you must skip the header portion (labels) of your file when reading.
    Next, it would be easier if your time was first, and your data was second in your columns, but that can be overcome. In the VI I am including, I have copied your data set into a file called data.txt, and I've removed the header and separated the columns with a tab. Then, I read in the data, and I break out each column so I can put the time first, and then I combine them again into a cluster so it can be displayed on an XY chart.
    Take a look!
    Mark"
    Graph data from file (Binary Executable, 20K)
    data.txt (Plain Text, 3K)
    This answer has not yet been rated.
    Rate this answer:
    Mikael Garcia on 9/11/2001 answered:
    "Ellie,
    Here is one way of doing it. Take a look at this example (compatible with LabVIEW 4.1 and up) and post comments if you need further help. Basically, I read your file as text; split it; and make use of the Spread sheet string to Array function before I plot your data. Hope this helps./ Mikael"
    ExtractAndPlot.vi (Binary Executable, 36K)
    This answer has not yet been rated.
    Rate this answer:
    Ellie on 9/12/2001 commented:
    "Thank you. I am trying to get the data from the text file into a string and am having some trouble. I am reading the file from a spreadsheet, and sending the output array to "Array to Spreadsheet String", but I'm not sure this is what I want to do. Is there another way to make an array into a string? Do I need to reformat my data?
    Can you offer me any advice?
    Thank you."
    data_1 (Plain Text, 3K)
    Mikael Garcia on 9/12/2001 commented:
    "I noticed that you changed your file format according to what was said here. Yes, this new file of yours is easier to use but your original file does not have to be changed. Take a look at this example. I now added the file-read part. It will give you a dialog to locate your data file (use this VI with your original file with the header since this VI includes a string split function). Hope this helps. /Mikael"
    ReadExtractandPlot.vi (Binary Executable, 35K)
    Niko on 9/12/2001 answered:
    "If you read this file with the "read from spreadsheet file.vi" you get you
    data in a 2-D-array. Now it is easy with array- and cluster-functions to
    handle the data the way you want.
    hope that helps, Niko"
    This answer has not yet been rated.
    Rate this answer:
    I intend to read from a .txt file that contains a column of numbers. After reading I want to display it as a waveform. In fact the numbers represent points along a waveform/graph of Flow vs. time. Thus I want to have this info in the chart or graph with flow in the y0axis and time in the x-axis. Can someone give me some detailed help please? Thank you in advance.
    Attachments:
    The_file.txt ‏18 KB

    All you have to do is use Read From Spreadsheet File.vi that's on the File I/O palette. For your example .txt, set the Transpose input to true and wire the First Row output to a waveform graph. The only problem I see is that since your file doesn't contain any sampling info, the time axis will be relative. If have that information elsewhere, then you can put a build waveform function between the read and the graph. Wire the First Row output to the Y input Build Waveform and add t0 and dt values. I've attached an example.
    Attachments:
    Graph_from_text.vi ‏29 KB

  • How can I read a specific character from a text file?

    Hi All!
    I would like to read a specific character from a text file, e.g. the 2012th character in a text file with 7034 characters.
    How can I do this?
    Thanks
    Johannes

    just use the skip(long) method of the input stream that reads the text file and skip over the desired number of bytes

  • How can I read a PC created disc of dbx files on a Mac

    I have a backup of my old e-mails on disc which I created on a PC (as .dbx files).
    I now need to refer to the e-mails, but I no longer have a PC.
    All guidance I have read appears to require the use of a PC to convert the .dbx files to .mbx before they can be read on the Mac.
    Does anyone know of a way of directly reading the disc on a Mac and accessing these files please.
    Many thanks. Bigtrev

    Only Pages, Preview, Pages for iCloud beta, and Pages v2 or later on IOS 7 can open native Pages v5.2.2 (.pages) documents. Sending a Pages v5.2.2 document to someone without Pages v5.2.2 is futile.
    If you are using Gmail or Dropbox, you will need to right-click on that Pages document, and then choose compress from the contextual menu. You can then attach filename.pages.zip, because it appears as a single document, and not a folder.
    Pages v5.2.2 has a Share button on the Toolbar. Providing your document is already in iCloud storage, you can Send a Link to iCloud via the following:
    The Share toolbar icon also allows you to Send a Copy to Email, Messages, and AirDrop. This will present you with the document export sheet, the same one you get if you chose to File > Export To menu item, as the alternative.
    If you are sharing document content with an MS Office user, then the document you want to send them is either a Word .docx, or .doc. If they want just a read-only view of your content, send a PDF, for improved cross-platform exchange.

  • Using Lab view ver 6,How can I read a cell of excel file right after I write to it

    How can I read a specif cell of an Excel file using Labview VI.

    Hi,
    Attached is a LV6.1 VI which will read a cell.
    It will be looking for a sub VI found in the example C:\Program Files\National Instruments\LabVIEW\examples\comm\ExcelExamples.ll​b.
    The returned value is a string value but there is no reason why it couldn't be a number. Just connect a numeric to the type connector of the Variant to Data function.
    Hope this helps.
    Regards
    Ray Farmer
    Regards
    Ray Farmer
    Attachments:
    Get_Cell_Value.vi ‏41 KB
    Write_Table_To_XL.vi ‏101 KB

  • How can I read the bootstrap files and extract the fragment-URLs and fragment-numbers in plain text?

    How can I read the bootstrap files of any HDS Live stream and extract the fragment-URLs and fragment-numbers in plain text?
    Could it be that it is some kind of compressed format in the bootstrap? Can I uncompress it wirh  f4fpackager.exe? Could not find any download for f4fpackager.exe. I would prefere less code to do so. Is there something in Java of JavaScript, that can extract the fragment-numbers?
    Thank you!

    Doesn't sound too hard to me. Your class User (the convention says to capitalize class names) will have an ArrayList or Vector in it to represent the queue, and a method to store a Packet object into the List. An array or ArrayList or Vector will hold the 10 user objects. You will find the right user object from packet.user_id and call the method.
    Please try to write some code yourself. You won't learn anything from having someone else write it for you. Look at sample code using ArrayList and Vector, there's plenty out there. Post in the forum again if your code turns out not to behave.

  • How can we read some bytes from every line of the file

    How can we read some bytes from the every line of the file moving on to the next line
    without using the read line

    Actualiy readLine() takes more execution time
    for reading a part of line if we can do so without
    readLine() we can save some time...Well, if you knew, beforehand, the length of each line, you could use RandomAccessFile and its seek method, but, since you don't, you would have to read the rest of the line character-by-character, checking to see if it is a newline, in order to place the "cursor" at the beginning of the next line in order to read the next few characters you want.
    So, as you can see, you will need to read the entire line anyway (and if you do it yourself you also have to do the checking yourself considering all three possible end-of-line sequences), so you just as well use readLine().
    Some people may suggest Scanner and it's nextLine() method, but that also needs to read the rest of line (as evidenced by the fact that it returns it), so that is no different than the readLine() (or read it yourself) solution.

  • How can I read from a file line by line?

    Hi!
    Could someone post some code or explain how can I read from a file, and want I to read a line each time. How can I go to line number N?
    Thanks

    hi,
    u can try this:
    try     {
          // open text file
          BufferedReader in = new BufferedReader(new FileReader(fileName));
          String line=in.readLine();
          while((line=in.readLine()) != null) {
          System.out.println(line);
          }The go to line number N i m not so sure.
    Cheers
    Jerry

  • How can I eliminate grid lines of selected cells when printing, in iOS numbers

    How can I eliminate grid lines of selected cells when printing, using iOS numbers

    Hi Cmlgfx,
    Thanks for visiting Apple Support Communities.
    You can style a table to remove grid lines and only show an "outline" around the table itself.
    See this article for help with table styles:
    Numbers for iOS (iPad): Place and style tables
    http://support.apple.com/kb/PH3365
    To show or hide the table name, table border, and grid lines, alternate row colors, or adjust fonts, tap Table Options at the bottom of the Table window (you may need to scroll up in the window to see it), and then set your preferences using the options in the Table Options window. (When you’re done, tap at the top of the window to see other options.)
    All the best,
    Jeremy

  • How can I have 2 versions of Numbers but only 1 app?  Read

    This is the weirdest thing I ever saw. It's driving me crazy and making me look like  fool.
    In an earlier post I mentioned that something happened to my numbers.  The window looked very different from this afternoon when I created 2 new spread-sheets.  I must have sounded crazy to qinn below in my answer.
    Now I clicked the Numbers icon in the dock and it opened to my original Numbers 09 (2.3).  So I tried to open a sheet I created a few hours ago and it says I can't open that file, I need a later version of Numbers. OMG
    Just a though so I opened the finder, went to the applications folder and I only have ONE Numbers.app.  So I clicked on that and low-and-behold the new 3.2.2 opened!!!!!!!
    How can I have 2 versions of numbers but only one app????  I thought I was going crazy.  Now I know something isn't right.
      HELP PLEASE!!!
    Allen

    Hi Allen,
    Look in your Applications folder for an other folder "iWork '09".
    Breathe.
    Know that you are not alone. Wayne made a user tip and it is not just for you.
    Need newer version of Numbers to open file
    quinn

  • When using large text my lines overpal, how can I increase the line spacing?

    When using large text my lines overpal, how can I increase the line spacing?

    Press 'Ctrl + Enter' after the numbered item to insert blank space below it. If you press 'Enter', the next line will start with the next number. As long as you want to type lines without a numbering, press 'Ctrl + Enter' and type the line.

  • How can I use more lines to show a field of a row in a report?

    How can I use more lines to show a field of a row in a report? Table A have two columns: (c1 number(5),c2 varchar2(1000)).When I show the table on a report,the column c2 show itself in one row.So the width of html page is very wide.How can I split the field c2 to many lines?
    Thanks for any help.

    I was wondering if an answer was found for this one.
    I have the same problem using the default "Look 4" template for the region. I have found in the CSS file where it is defined and it specifies "nowrap" in the style, which is why the long value is not being split over multiple lines.
    So, my question is, without modifying or creating templates, is there a way to override the "nowrap" attribute from within the item definition? e.g. in the Column Attributes.Column Formatting.CSS Style field. I had some success changing the display properties, such as background colour and font size but I can't seen to override the nowrap attribute!

  • How can I read pdf files from LabVIEW with different versions of Acrobat reader?

    How can I read pdf files from LabVIEW with different versions of Acrobat reader?
    I have made a LabVIEW program where I have possibility to read a PDF document.  When I made this LabVIEW program it was Acrobat Reader 5.0.5 that was installed on the PC. Lather when the Acrobat Reader was upgraded to version 6.0, there was an error when VI tries to launch the LabVIEW program. And Later again when we upgraded to Acrobat Reader 7.0.5 I must again do some changes and rebuild the EXE files again
    It isn't so very big job to do the changes in one single LabVIEW program, but we have built a lot of LabVIEW programs so this take time to due changes every time vi update Acrobat Reader. (We have build EXE files.)
    The job is to right click the ActiveX container and Click "Insert ActiveX Object", then I can brows the computer for the new version of acrobat Reader. After this I must rebuild all the "methods" in the Activex call to make the VI executable again.
    Is there a way to build LabVIEW program so I don't have to do this job every time we update Acrobat Reader?
    This LabVIEW program is written in LabVIEW 6.1, but I se the problem is the same in LabVIEW 8.2.
    Jan Inge Gustavsen
    Attachments:
    Show PDF-file - Adobe Reader 7-0-5 - LV61.vi ‏43 KB
    Read PDF file.jpg ‏201 KB
    Show PDF-file - Adobe Reader 5-0-5 - LV61.vi ‏42 KB

    hi there
    try the vi
    ..vi.lib\platform\browser.llb\Open Acrobat Document.vi
    it uses DDE or the command line to run an external application (e.g. Adobe Acrobat)
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"

  • How can i read a stored picture in oracle Long Raw datatype? blob or clob?

    How can i read a stored picture in oracle Long Raw datatype? Like a blob or clob?....i am using jdk 1.3
    This is because...i tried to read it like a blob but i obtain a exception...about Type of column no valid......but the column exist....and it contains the long raw datatype of the pictures.....this is my code:
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    import oracle.jdbc.driver.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.InputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.DriverManager;
    import oracle.sql.BLOB;
    import oracle.sql.BLOB.*;
    import oracle.jdbc.driver.*;
    import java.sql.*;
    class rec_ima1
    public static void main(String h[])
    Connection con = null;
    Blob bl;
    final ImageIcon image1;
    JPanel photo;
    try
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    con= DriverManager.getConnection("jdbc:oracle:thin:@123.3.12.213:1521:db_name","user","password");
    String query = "Select * from pictures where ID = '18840'";
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery( query );
    if (!rs.next())
    System.out.println("Empty Result Set");
    bl = rs.getBlob(5);
    if (bl == null) {
    System.out.println("Null Blob");
    return;
    InputStream is = bl.getBinaryStream();
    int imageLength = (int) bl.length();
    System.out.println(imageLength);
    System.out.println(bl.length());
    byte[] imageData = new byte [imageLength];
    is.read(imageData, 0, imageLength);
    image1 = new ImageIcon(imageData);
    photo = new JPanel() {
    public void paint(Graphics g){
    g.setColor(Color.lightGray);
    g.drawImage(image1.getImage(), 0, 0, this);
    } catch (Exception e) {
    e.printStackTrace();
    Now i tried using clob:
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    import oracle.jdbc.driver.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.InputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.DriverManager;
    import oracle.sql.CLOB;
    import oracle.sql.CLOB.*;
    import oracle.jdbc.driver.*;
    import java.sql.CallableStatement;
    class rec_ima4
    public static void main(String h[])
    Connection con = null;
    Clob cl;
    JPanel photo;
    try
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    con= DriverManager.getConnection("jdbc:oracle:thin:@123.3.12.213:1521:db_name","user","password");
    con.setAutoCommit (false);
    String query = "Select * from pictures where ID = '18840'";
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery( query );
    while (rs.next()) {
    oracle.sql.CLOB clob = (CLOB) rs.getObject(5); //line 47
    } catch (Exception e) {
    e.printStackTrace();
    This is the runtime exception:
    java.lang.ClassCastException: [B
    at rec_ima4.main(rec_ima4.java:47)

    Thanks by answering to me......
    Well....i did that....but what is ImageIO?....
    I declared a ImageIcon imageIO, but this give me the following:
    rec_ima3.java:49: cannot resolve symbol
    symbol : class BufferedImage
    location: class rec_ima3
    BufferedImage bi = ImageIO.read(bInput);
    ^
    rec_ima3.java:49: cannot resolve symbol
    symbol : variable ImageIO
    location: class rec_ima3
    BufferedImage bi = ImageIO.read(bInput);
    ^
    What classes i have to import?.....what is ImageIO?
    Thanks

Maybe you are looking for

  • Getting Error while importing catalog xml

    Hi , i am new to ATG. I am getting the below error when i tried to import the xml. D:\ATG\ATG9.0\home>bin\startSQLRepository -m DynamusicB2C -import ..\DynamusicB2C\config\dynamusic\DynamusicB2CData.xml -repository /atg/commerce/catalog/ProductCatalo

  • Derivation of Functional Area in FI document

    Hi We have an issue with the Functional Area derivation while posting the FI document. One FI document got posted with 4 line items, with 3 GL accounts. Two line items are from one GL(Which has cost center) and remaining two belongs to other GL accou

  • How do I change the name and author of the book I have downloaded?

    I have bought and downloaded a book which has turned up in my library with the title Dokument1 and the author as Pero - to say the least, not correct.  How can I change the name so I know what it actually is and who actually wrote it?  Gotta say - I'

  • Re: Pressing FN+F5 message: IGFXEXT module has stopped working

    When i press Fn F5 i get the message IGFXEXT module has stopped working and i cannot change my monitor configuration. I briefly see the icons but when i cancel the error message they disappear. I have downloaded and install ed the 09/10/08 Intel Driv

  • 9_04 or 9_2 should I choose

    Hi All, Our company will start to use OWB to build a project. We have some experience about 9_04 and Oracle has 9_2 released. Shall we use 9_2 to do development for our Data Warehouse. Rd, CH