How to read from file just the 2nd line onwards?

hi guys can anyone help me?
how to read from the file if the file was like this
2 2
2 1
1 3
and i want to get the 2 1 ,just the 2nd line and the 3rd line?
i tried using the string tokenizer but it kept saying
no such element
i tried this code:
StringTokenizer cols = new StringTokenizer(s," ");
     temp =  (String) (cols.nextElement());
     num_rows = Integer.parseInt(temp);
     temp = (String) (cols.nextElement());
     num_cols = Integer.parseInt(temp);
     matrix = new int [num_rows][num_cols];
     // to add all the values in the data file into an array                         
     while ( s!= null ) {
     StringTokenizer st1 = new StringTokenizer (s);
           while (st1.hasMoreTokens()){
                 for (i=0; i<num_rows; i++){
                      for (j=0; j<num_cols; j++)
                         matrix[i][j] = Integer.parseInt
                            ( st1.nextToken());
            } // whilecan anyone please help me?
thanks

This will read the file witout the first line:
import java.io.*;
import java.util.*;
public class Read2
public static void main (String[] args)
     try
          FileReader     file = new FileReader("f.txt");
          BufferedReader buff = new BufferedReader(file);
          String         line  = buff.readLine();
          while (line != null)
               line = buff.readLine();
               System.out.println(line);
          buff.close();
     catch(IOException e)
          System.out.println("IO Error");
}       Noah

Similar Messages

  • How to read a file just from middle?

    I want to read a file which has 200,000 lines. And I want to read it from 100,000, but I don't want to read it from begining. So I use LineNumberReader class, but it failed. The code:
    LineNumberReader lnr=new LineNumberReader(new InputStreamReader(src_lob.getBinaryStream()));
             lnr.setLineNumber(5);
             String line="";
             while((line=lnr.readLine())!=null)
                     System.out.println(line);
             } How to change the code???

    Random Access File will be good option I think
    filelength=RandomAccessFile.length();
    raf.seek(filelength/2);
    then read file characters

  • How to read from file?

    I have one file, let's say it contain:
    1 2
    1 4
    2 3
    It named "filename.txt"
    How to read the data from the file?
    Here is example of my code.
    byte buf[] = new byte[38];
              try {
                   FileInputStream in = new FileInputStream("filename.txt");
                   in.read(buf);
              catch (Exception e) {
              System.out.println(e);
              String s = new String(buf);
              //int x = Integer.parseInt(s);
              System.out.print(s);
    It can print it out according to the contents of the file. The problem is I want the contents become separate, i mean the first column will be saved into first int array, and the second arrat will be in second integer array. Thus 1st array will contains 1,1,2 and the 2nd will contains 2,4,3. I don't want it in the String format. In my code example is in the string format. Anyway can help me out?
    Thanks.

    Hi,
    Take a look at the sample code below:
    BufferedReader in
       = new BufferedReader(new FileReader("file.txt"));
    String row = null;
    while ((row = in.readLine()) != null) {
        String[] parts = row.split(" ");    //part now contains the two values as strings. Use Integer.parseInt to parse them.
        System.out.println("got row " + row);
    }/Kaj

  • How to read some files inside the jar

    Hi,
    I have an applet that runs with JWS. The user can input some information and then I need to show this information in a web page. As the application can be run offline, I cannnot use JSP�s to generate the web page. The information is saved in a xml file, so I use a xsl parser to generate the html code. The problem is that I have to include some javascript files (.js). I put these files inside the jar, but, how can I read these files, or how can I reference these files from inside the html page ?
    Thanks !

    You can use getClass().getResource(classpath)
    to get a stream version of the data from your
    jar file. If you need to put it in a file, you
    can write that stream to a file in a temp directory.
    classpath is the classpath of your js file

  • How to read a file inside the JAR file

    Hi All,
    I want to save some preferences in a file called "preferences". I kept the preferences file under my java package.
    If i am running the code inside the NetBeans 6.9 IDE it's working file. But once i have created a JAR and try to run the application, it couldn't find the path.
    Please help me that how to resolve this issue. I don't want to save this preferences file outside of my JAR (i.e) within my java package.
    Here is the code,
    package mypackage;
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.PrintWriter;
    public class ReadFile
        private void writeFile()
            try
                OutputStream out = new FileOutputStream(getClass().getClassLoader().getResource("mypackage/preferences").getPath().replace("%20", " "));
                PrintWriter writer = new PrintWriter(out);
                writer.println("Hello Java!");
                writer.close();
                out.close();
            catch (Exception ex)
                System.out.println(ex.getMessage());
        private void readFile()
            try
                FileInputStream fi = new FileInputStream(getClass().getClassLoader().getResource("mypackage/preferences").getPath().replace("%20", " "));
                BufferedReader br = new BufferedReader(new InputStreamReader(fi));
                System.out.println(br.readLine().trim());
                br.close();
                fi.close();
            catch (Exception ex)
                System.out.println(ex.getMessage());
        public static void main(String[] args)
            ReadFile read = new ReadFile();
            read.writeFile();
            read.readFile();
    }If i run the JAR, i get the following error message,
    {color:#ff0000}*file:\my jar path\jarname.jar!\mypackage\preferences (The filename, directoryname, or volume label syntax is incorrect)*{color}

    Thanks sabre150,
    sabre150 wrote:
    You cannot update a running jar file. I am sorry. I didn't know about it. Thanks to point out.
    There are two ways I approach this depending on my exact requirements -
    1) use the java.util.prefs.Preferences APII will try this one
    >
    2) if not already present I copy the preferences file from the jar to a known place. I use a directory in the user's home directory and normally make the directory name the program with a '.' prefix.
    One cannot access files in a jar file using the File API. One needs to use the getResource() or getResourceAsStream() methods on Class or ClassLoader.

  • How to read resource file under the WEB-INF through ClassPathResource

    I have an xml file under the directory WEB-INF but WEB-INF/classes, I want to read it through ClassPathResource class from Spring, and where I read this xml file is not in a Servlet class, how can I do? Thank you.

    Webmethods should be able to handle it. if not you should convert the tline content into one xstring and pass it to webmethods.
    othe option
    if you are on WAS6.20 and above you can use BSP to achieve what you are looking for.
    Regards
    Raja

  • How to read multiple files in the same folder?

    Suppose I have 100 txt files in the same folder, and I want to read them one by one. (order is not important). File name is also part of the information I want.
    How to do that?
    Thanks

    You need to use the directory to create a File (use the path name, w/o a file name). Then you need to ask for a list() (array of String containing name). To do that you'll need to implement the FilenameFilter interface, writing an accept() method that returns true if the file's name ends with ".txt".
    If that's not perfectly clear, try the java.io API docs and return more specific questions.

  • How to read, write file inside the JAR file?

    Hi all,
    I want to read the file inside the jar file, use following method:
    File file = new File("filename");
    It works if not in JAR file, but it doesn't work if it's in a JAR file.
    I found someone had the same problem, but no reply.
    http://forum.java.sun.com/thread.jsp?forum=22&thread=180618
    Can you help me ? I have tried this for all night !
    Thanks in advance
    Leo

    If you want to read a file from the JAR file that the
    application is packaged in (rather than a separate
    external JAR file) you do it like this ...
    InputStream is =
    ClassLoader.getSystemResourceAsStream("filename");Better to use
    this.getClass().getClassLoader().getResourceAsStream();
    From a class near to where the data is. This deals with multiple classloaders properly.

  • Read from file and plot data against timestamp

    Hello,
    I know that there are already many posts regarding the question I m about to ask. But, I somehow dont seem to achieve what I want using the suggestions given in the other posts.
    My problem is that, I have a file with the first column as a time stamp containing hour, minute, second and millisecond. The second column in a set of pressure values. I want to plot a graph of these pressure values against the timestamp recorded in this .txt file. Whatever I do, the timestamp values seem to skip by a couple of seconds.
    How do i do this correctly?
    Also, Is it advisable to use the read from file or the read from spreadsheet file vi? Kindly help me out.
    Thanks and regards.

    Hey, I was having a similar issue the other day.  The first problem I had was how to open the file and actually get the timestamp information.  Since I'm using LabView 8.0, I had to go into Read Spreadsheet File and create a new vi to open strings (in an array form).  That's the Read Spreadsheet File (string) vi below.  Then, I had to figure out how to convert the string of a timestamp to something meaningful to me.  The Timestamp2.vi is how I did that below.  I'm also including a little test file.  So, to run Timestamp2.vi, you will have to input the right base path, and have the Read Spreadsheet File (string).vi in the same place as Timestamp2.  Hope that helps.  I think I'm finally getting this stuff, so let me know if it doesn't work.
    Attachments:
    Test.txt ‏1 KB
    Timestamp2.vi ‏28 KB
    Read From Spreadsheet File (String).vi ‏25 KB

  • How to indent the 2nd line of a long string?

    Hi all,
    I would like to achieve something like below where the 2nd line will be indented automatically. How to do format this in Oracle Report? The "<--indent-->" below is to illustrate the indentation, which I can't show in this posting as the formatting is not supported.
    Okuda, M., & Okuda, D. (1993). Star Trek chronology: The history of the
    <--indent--->future. New York: Pocket Books.
    Please advise.
    Thank you.

    Yes, chr(10) can make the string break to next line, but that cannot fulfill my requirement.
    What I need is a single long string that will automatically get indented for the 2nd line onwards when display in report.
    I can't use chr(10) because I won't know when to break to next line because it does not have fixed rule that after which part should I break it to next line. I'm referring to bibliographic citation that normally display as indented for the 2nd line.
    Hope you got what I mean.

  • How to read .xml file from embedded .swf(flash output) in captivate

    I have been trying to read .xml file from the .swf (Flash output) that is embedded within the captivate file but no luck yet . Please if anyone got any clue on how get this thing done using Action script 3.0 then let me know. I am using Adobe Captivate 5.5 at present and Flash CS 5.5.
    I am well aware about how to read .xml file through action script 3.0 in flash but when insert the same flash in captivate and publish nothing comes in captivate output. I would higly appreciate if anyone could help me out with that.
    Here is is graphical demonstration of my query :
    Message was edited by: captainmkv

    Hi Captainmkv,
    Does the information in this post cover what you're trying to do: http://forums.adobe.com/message/5081928#5081928
    Tristan,

  • How to read from a file

    hello friends i m a newbie in java n as i m self studying java, i got stuck on the input streams.sir could u please help me how to read a file named test.txt from following code.
    import java.io.*;
    class ShowFile {
    public static void main(String args[])
    throws IOException
    int i;
    FileInputStream fin;
    try {
    fin = new FileInputStream(args[0]);
    } catch(FileNotFoundException exc) {
    System.out.println("File Not Found");
    return;
    } catch(ArrayIndexOutOfBoundsException exc) {
    System.out.println("Usage: ShowFile File");
    return;
    // read bytes until EOF is encountered
    do {
    i = fin.read();
    if(i != -1) System.out.print((char) i);
    } while(i != -1);
    fin.close();
    }

    sir i heartly appericiate ur quick response the problem in above code is that i have copied the above code from a book which i m reading but it hasn't included any file for reference whch i can test the code upon ie when it is being compiled n runned the no file found error is indicated

  • How to read from text file?

    I would like to read data (frequencies) already written in a text file. I will need read these frequencies one at a time to set the function generator (as part of my data acquisition application), acquire data that is in turn written to a file and then go back and read the next frequency from the file to repeat the process again. I also have another idea of doing the same, which is read all the frequencies from the text file and populate a table and a frequency value is picked from the table each time to go through the process mentioned above.
    Can anyone suggest the following: (1) How to read from a text file, (2) What could be the most efficient way of solving my above problem.
    I am a new LabVIEW user and any help will be appreciated.

    Hi Research,
    Depending on the format of the data file, there are a few options for reading it.  If it is tab delimited, you may want to use the Read from SpreadSheet File VI which will read the file into an Array.  You can then use the Index Array VI to pull out individual entries.  If the files is ASCII but not tab delimited, you could use the regular Open File and Read File VIs.  You can either read the file out piece by piece, or read the entire file into a string and then use the Match Pattern VI to parse out the different elements (there are actually many ways to do this - check out the Strings subpalette). 
    Since you're new to LabVIEW, you may want to check out these resources:
    Three Hour Introduction to LabVIEW
    Six Hour Introduction to LabVIEW
    Getting Started with LabVIEW
    I hope this helps!  Let us know if you have more questions,
    Megan B.
    National Instruments

  • How to read from properties file

    Hi,
    I am using JSR 168.
    while creating a new portlet, a folder gets created with the name as "portlet". Under which is resource package and <PortletName>Bundle.java.
    pls tell me how to read from .properties file.
    waiting eagerly for some reply
    Thanks & Regards,
    HP
    Edited by: user9003827 on Apr 13, 2010 3:42 AM

    I think i have mixed it up :)
    I have looked at it again and believe you are using regular JSP portlets.
    Can you tell what you want to achieve by reading .properties file. Are you meaning the preferences of the portlet or what exactly are you trying to do?
    Reading propertie files is easy:
    // Read properties file.
    Properties properties = new Properties();
    try {
        properties.load(new FileInputStream("filename.properties"));
        String myKey = properties.getProperty("yourKey");
    } catch (IOException e) {
    }Edited by: Yannick.O on 13-Apr-2010 05:52

  • Adobe Illustrator CS4 Error: Error 1603. Error 1305.Error reading from file C:\Program Files\Adobe\Adobe Illustrator CS4\Support Files\Required\Fonts\AdobeSongStd-Light.otf.  Verify that the file exists and that you can access it.  AdobeColorCommonSetRGB

    Iam trying to load illustator in my PC i get following error while loading Application CD 2
    Adobe Illustrator CS4
    Error:
    Error 1603. Error 1305.Error reading from file C:\Program Files\Adobe\Adobe Illustrator CS4\Support Files\Required\Fonts\AdobeSongStd-Light.otf. Verify that the file exists and that you can access it.
    AdobeColorCommonSetRGB
    Error:
    Error 2.
    My serial no. [Removed by moderator]

    Download a copy an installer for CS4 from the links on this page:
    Other downloads

Maybe you are looking for

  • Using Session EJB from MDB in Weblogic 11G

    I am having trouble with what should be a very simple operation. I have created an MDB and deployed it successfully on the Weblogic managed server. Then in a separate application, I created a Stateless session bean that I would also like to call from

  • Component colouring  in ADF

    hi folks, i h've a one requirement and i also have one problem as i already filed here. first my problem sorry for hooking this link. Problem in Drag and Drop Requirement(af:calendar) and my Requirement. i want to put different color in af:calendar c

  • Automatically splitting documents into Html files

    Hi, I would like to generate several HTML files from a single FM document. Splitting should be done at the 'Heading 1' paragraph level, or the like. By reading the program's documentation, it seems FM9 can do this splitting automatically: in "Generat

  • Issue on Using TOAD to view Oracle10G objects

    Dear Oracle Expertise, I've a interesting topic here. I use a TOAD's schema browser feature to view all the objects (e.g. tables, views, triggers, etc...) in an Oracle10G database. The issue is that it seems there is NO SORTING order of these objects

  • What is the order for install of the 16cd's for version 7.1?

    There are about 16 cd's required for the complete install of my corporate 7.1 version. Does anyone know which cd's need to be installed and what sequence of install is needed?