Read from file, line number N?

Could someone post some code or explain how can I read from a file, line number N?
Thanks

this is a simple way but not so professional:
string filename="";// file name
try{
int N=5;// line number to read first line is line 0
File file=new File(filename);
BufferedReader in=new BufferedReader(new FileReader(file));
for(int x=0;x<N;x++){
in.readLine();
String lineN=in.readLine();
catch(..){
Alex

Similar Messages

  • Loop:  reads from file line by line

    This works:
    String line= f.readLine();
    while (line != null) {
    System.out.println(line);
    line= f.readLine();
    However, I want to get rid of the leading and trailing white space, hence
    String line= f.readLine().trim();
    while (line != null) {
    System.out.println(line);
    line= f.readLine().trim(); <--error
    So, it gives me a NullPointerException. I don't understand why it gives me this exception on the last line that it reads. The last line is not empty, is it?

    When in doubt read the API!!!
    When you do that you will see that readLine() method on a BufferedReader returns null when it has nothing more to read. So it does read the last line which is non-null, then returns null on the next invocation. You want to test if line is null before assuming it is a String object and trying
    to call trim() on it.

  • Read the file line by line from upload

    Hi Guys,
    Need help... I creating a web application that has a upload capability. What I want to do is this...
    I want to upload a file (but not save it). What I'm going to do is just read the file line by line and save these data to the database. How can I do this? (BTW, I'm using struts (FormFile)).
    Please guide me please!
    Thanks.

    i think u should obtain a inputstream from request object and then save it to the database using BLOB object.

  • Reading a file line by line from right to left using StringTokenizer

    I hope the title caught you attention!!!
    I am a little stuck. How can I implement a method that will allow me to read a sentence from right to left when reading from file.
    Ex.
    IX: Series      {2}
    IX: {Series!geometric|(}      {4}
    IX: {Euler's constant}      {4}
    IX: {Series!geometric|)}      {4}
    IX: {Series!arithmetic|(}      {4}
    IX: {Series!arithmetic|)}      {5}
    IX: {Series!harmonic|(}      {5}
    IX: {Euler's constant}      {5}
    IX: {Series!harmonic|)}      {5}
    IX: Series      {5}
    So for example in the first row we have
    IX: Series      {2}
    and what the output should show be is
    Series: 2
    What happens in the background is that I created an entry for a TreeMap which will be display at the end.
    Thanks for your time and appreciate your help kindly.

    Well, as a left-to-right start:
    public class TopicInputReader extends BufferedReader {
        public static final int STARTTOPIC = 0;
        public static final int ENDTOPIC   = 1;
        public static final int SUBTOPIC   = 2; 
        // Instead of making Topic members public, you should make accessors.
        // Didn't feel like typing.
        public class Topic {
            public int    type; // STARTTOPIC, ENDTOPIC, or SUBTOPIC
            public String name;
            public String parent;
            public int    page;
        public TopicInputReader (Reader in) {
            super(in);
        public TopicInputReader (Reader in, int sz) {
            super(in, sz);
        public Topic readTopic () throws IOEXception {
            String          line;
            Topic           topic;
            StringTokenizer tokens;
            String          token;
            line = readLine();
            if (line = null) throw new EOFException();
            tokens = new StringTokenizer(line);
            topic.parent = "".intern();
            // Note: If StringTokenizer isn't appropriate for you, you
            // can use a StringReader in conjunction with a StreamTokenizer.
            // Ex: token = new StreamTokenizer(new StringReader(line));
            // TODO: Set up tokenizer parameters here.
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken(appropriate_delimiter);
                // TODO: Fill in 'topic' fields here.
                // Keep in mind, since you're reading left-to-right and you don't
                // know if a particular string is going to be a topic name or a
                // sub topic, you can always just read a topic name into topic.name
                // and, when you encounter a new topic name:
                //    topic.parent += ('!' + topic.name);
                //    topic.name = token;
            return topic;
    };I definitely have not tested that... or even double-checked it.
    Although... the format of your topic list file does lend itself well to right-to-left parsing. Since you are insisting, I suggest reversing the string and using a StringTokenizer (or a StreamTokenizer and a StringReader):
        BufferedReader  r = new BufferedReader(new InputStreamReader(myInputStream));
        String          line, revline;
        StreamTokenizer tokens;
        while (...) {
            line    = r.readLine();
            revline = (new StringBuffer(line)).reverse().toString();
            tokens  = new StreamTokenizer(new StringReader(line));
            // Parse tokens here.
        };Jason

  • What is the best way to read a file line by line?

    Hello, everyone!
    I want to read a file line by line, i.e. each time, a line of a text file is read and stored as a String object and the String object will be manipulated (parsed) later.
    I have found that FileInputStream does not have a function which is responsible for reading a line each time from a text file. Anyone have good suggestions?
    Best regards,
    George

    I always use the following example.. mayb that would help you as well
    File fid = new File(fileName);
    if (fid.exists())
            fr = new FileReader(fid);
            br = new BufferedReader(fr);
             while((txtstr= br.readLine()) != null)
    }

  • SapScript, How do I read the current line number?

    I have sections of text - each in it's own element with an 'include' of the standard text.
    These sections are variable in size.
    All elements are in the MAIN window.
    I do not want a paragraph to split over two pages.
    How do I read the current line number within the sapscript before the section prints so I can issue a new-page command at the beginning of the paragraph?
    Thanks!

    Yes, that does work for paragraphs.
    If I have multiple elements to print from within a loop where "at first, at each and at last" each call the Sapscript funtcion write_form - how can I keep the whole section together.  protect/endprotect will keep each element together but not the group of elements.
    There must be a way to find the current line number.

  • Error reading from file glibc-2.5-24.i686.rpm RHEL 5 Setup stuck at 80%

    Hi, I am installing Oracle 10g on RHEL 5 (Red Hat Enterprise Linux 5) machine I am facing two problems
    1) while installing the rpm packages the following package gave an error
    Error reading from file glibc-2.5-24.i686.rpm
    2) I still gave a try to runInstaller command the installer opened but was stuck at 80%
    I have 3 GB ram and 320GB hard drive I am not sure what to put in the swap memory and other settings i blindly followed instructions given here
    http://www.oracle-base.com/articles/10g/OracleDB10gR2InstallationOnRHEL5.php
    What could be the problem where do I find the error log if its created
    Please help me
    Thanks
    Edited by: 891355 on Nov 6, 2011 12:06 PM

    I found the installActions file in the installer folder and I think this could be the problem
    INFO: The 'shiphomeproperties.xml' file is missing from shiphome location '/home/oracle/Desktop/database/install/../stage/products.xml.' Add this file to the 'Disk1/stage' directory of the shiphome.
    though I am attaching the log file for more details do you think the installer is corrupt :(
    InstallActions log file ==> http://www.mediafire.com/?nh7mx7bxqht9ovu
    Edited by: 891355 on Nov 6, 2011 1:35 PM

  • [Error] Microsoft SQL Server 2008 Setup. Error reading from file msdbdata.mdf

    Hi all
    I'm trying to install SQL 2008 Express on my Computer: Hp compact DX7300 Slim tower.
    and get this error:
    TITLE: Microsoft SQL Server 2008 Setup
    The following error has occurred:Error reading from file d:\8268cd7b247d294de359c9\x86\setup\sql_engine_core_inst_msi\PFiles\SqlServr\MSSQL.X\MSSQL\Binn\Template\msdbdata.mdf.  Verify that the file exists and that you can access it.
    Click 'Retry' to retry the failed action, or click 'Cancel' to cancel this action and continue setup.
    For help, click: http://go.microsoft.com/fwlink?LinkID=20476&ProdName=Microsoft+SQL+Server&EvtSrc=setup.rll&EvtID=50000&ProdVer=10.0.1823.0&EvtType=0xF45F6601%25401201%25401
    Log file
    Overall summary:
      Final result:                  SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup.
      Exit code (Decimal):           -2068643839
      Exit facility code:            1203
      Exit error code:               1
      Exit message:                  SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup.
      Start time:                    2014-12-09 23:22:03
      End time:                      2014-12-09 23:40:28
      Requested action:              Install
      Log with failure:              C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20141209_232121\sql_engine_core_inst_Cpu32_1.log
      Exception help link:           http://go.microsoft.com/fwlink?LinkId=20476&ProdName=Microsoft+SQL+Server&EvtSrc=setup.rll&EvtID=50000&ProdVer=10.0.1823.0
    Machine Properties:
      Machine name:                  VISTA-PC
      Machine processor count:       2
      OS version:                    Windows Vista
      OS service pack:               Service Pack 1
      OS region:                     United States
      OS language:                   English (United States)
      OS architecture:               x86
      Process architecture:          32 Bit
      OS clustered:                  No
    Product features discovered:
      Product              Instance             Instance ID                    Feature                
                     Language             Edition              Version         Clustered 
    Package properties:
      Description:                   SQL Server Database Services 2008
      SQLProductFamilyCode:          {628F8F38-600E-493D-9946-F4178F20A8A9}
      ProductName:                   SQL2008
      Type:                          RTM
      Version:                       10
      SPLevel:                       0
      Installation location:         d:\8268cd7b247d294de359c9\x86\setup\
      Installation edition:          EXPRESS
    User Input Settings:
      ACTION:                        Install
      ADDCURRENTUSERASSQLADMIN:      False
      AGTSVCACCOUNT:                 NT AUTHORITY\NETWORK SERVICE
      AGTSVCPASSWORD:                *****
      AGTSVCSTARTUPTYPE:             Disabled
      ASBACKUPDIR:                   Backup
      ASCOLLATION:                   Latin1_General_CI_AS
      ASCONFIGDIR:                   Config
      ASDATADIR:                     Data
      ASDOMAINGROUP:                 <empty>
      ASLOGDIR:                      Log
      ASPROVIDERMSOLAP:              1
      ASSVCACCOUNT:                  <empty>
      ASSVCPASSWORD:                 *****
      ASSVCSTARTUPTYPE:              Automatic
      ASSYSADMINACCOUNTS:            <empty>
      ASTEMPDIR:                     Temp
      BROWSERSVCSTARTUPTYPE:         Disabled
      CONFIGURATIONFILE:             C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20141209_232121\ConfigurationFile.ini
      ENABLERANU:                    True
      ERRORREPORTING:                False
      FEATURES:                      SQLENGINE,REPLICATION
      FILESTREAMLEVEL:               0
      FILESTREAMSHARENAME:           <empty>
      FTSVCACCOUNT:                  <empty>
      FTSVCPASSWORD:                 *****
      HELP:                          False
      INDICATEPROGRESS:              False
      INSTALLSHAREDDIR:              C:\Program Files\Microsoft SQL Server\
      INSTALLSHAREDWOWDIR:           C:\Program Files\Microsoft SQL Server\
      INSTALLSQLDATADIR:             <empty>
      INSTANCEDIR:                   C:\Program Files\Microsoft SQL Server\
      INSTANCEID:                    SQLExpress
      INSTANCENAME:                  SQLEXPRESS
      ISSVCACCOUNT:                  NT AUTHORITY\NetworkService
      ISSVCPASSWORD:                 *****
      ISSVCSTARTUPTYPE:              Automatic
      MEDIASOURCE:                   d:\8268cd7b247d294de359c9\
      NPENABLED:                     0
      PID:                           *****
      QUIET:                         False
      QUIETSIMPLE:                   False
      RSINSTALLMODE:                 FilesOnlyMode
      RSSVCACCOUNT:                  <empty>
      RSSVCPASSWORD:                 *****
      RSSVCSTARTUPTYPE:              Automatic
      SAPWD:                         *****
      SECURITYMODE:                  <empty>
      SQLBACKUPDIR:                  <empty>
      SQLCOLLATION:                  SQL_Latin1_General_CP1_CI_AS
      SQLSVCACCOUNT:                 NT AUTHORITY\NETWORK SERVICE
      SQLSVCPASSWORD:                *****
      SQLSVCSTARTUPTYPE:             Automatic
      SQLSYSADMINACCOUNTS:           VISTA-PC\VISTA
      SQLTEMPDBDIR:                  <empty>
      SQLTEMPDBLOGDIR:               <empty>
      SQLUSERDBDIR:                  <empty>
      SQLUSERDBLOGDIR:               <empty>
      SQMREPORTING:                  False
      TCPENABLED:                    0
      X86:                           False
      Configuration file:            C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20141209_232121\ConfigurationFile.ini
    Detailed results:
      Feature:                       Database Engine Services
      Status:                        Failed: see logs for details
      MSI status:                    Passed
      Configuration status:          Passed
      Feature:                       SQL Server Replication
      Status:                        Failed: see logs for details
      MSI status:                    Passed
      Configuration status:          Passed
    Rules with failures:
    Global rules:
    Scenario specific rules:
    Rules report file:               C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20141209_232121\SystemConfigurationCheck_Report.htm
    I will very appriciate if someone can help me solve it. I was trying to set Full control for my account in Properties/Security of root folder and try again but error is still.
    Many thanks

    Hi Foreverduy,
    Before you run SQL Server 2008 express setup, make sure that you have installed Windows installer 4.5 and.NET Framework 3.5 SP1 manually. For more information about the process, please refer to the article:
    http://msdn.microsoft.com/en-us/library/ms143506(v=sql.100).aspx. Moreover, please turn off all the third-party softwares which could prohibit the installation process.
    According to your error message, the issue could be due to that your account has no rights to install SQL Server, or the corruption on the media.
    Firstly, please ensure that your account has admin rights. Also make sure that you right-click the setup.exe and choose “Run as administrator” to complete the installation.
    Secondly, please check if "msdbdata.mdf" file exists at d:\8268cd7b247d294de359c9\x86\setup\sql_engine_core_inst_msi\PFiles\SqlServr\MSSQL.X\MSSQL\Binn\Template. If it exists, please make sure that your account has read permission to the extracted
    folder.
    However, if the file doesn't exist in the extraction, the media could be corrupt. Please download the
    media
    again and check if the issue still occurs.
    Regards,
    Michelle Li

  • 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

  • How to read a file line by line in UTL

    Hi All,
    DECLARE
    fileID UTL_FILE.FILE_TYPE;
    strbuffer VARCHAR2(100);
    BEGIN
    fileID := UTL_FILE.FOPEN ('DR', 'New.txt', 'R');
    UTL_FILE.GET_LINE (fileID, strbuffer);
    dbms_output.put_line(strbuffer);
    END;
    By this program I can read only first line of the file. I want to read the file line by line.
    Thanks
    Sunil

    try this
      DECLARE
        fileID UTL_FILE.FILE_TYPE;
        strbuffer VARCHAR2(100);
      BEGIN
        fileID := UTL_FILE.FOPEN ('DR', 'New.txt', 'R');
        if utl_file.is_open(fileID) THEN
          loop
            UTL_FILE.GET_LINE (fileID, strbuffer);
            dbms_output.put_line(strbuffer);
            if strbuffer IS NULL THEN
              exit;
            end if;
          end loop;
        end if;
      END;note: untested.

  • 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

  • Web Service; Error attempting to read from file

    I'm trying to connect to a web service as outlined by the book "Creating Dynamic Forms with Adobe LiveCycle Designer" which is an excellent book by the way.
    I'm receiving the following error "Error attempting to read from file. http://www.webservicex.net/BibleWebservice.asmx"
    I've successfully created the Data Connection to
    http://www.webservicex.net/BibleWebservice.asmx?wsdl
    I dragged and dropped the bookTitle, chapter & Versie onto the form. I also dragged and dropped the GetBibleWordsByChapterAndVerseResult and the GetBibleWordsByChapterAndVerseBtn.
    I Preview PDF and click the button I get the above error.
    Does anyone have experience using Web Services with Adobe LiveCycle ES and have advice on how to resolve this. Any Suggestions would be greatly appreciated.
    -Todd

    Well, I have more news on the error I'm getting. - NO I didn't find the problem. Yet
    I checked and made sure that web.config had "None" selected " in authentication mode. I.E. <authentication mode="None" /> This should eliminate any authentication problems since that turns off IIS's authentication checking.
    At first I was thinking the form was generating the error trying to read the result coming back from the web service, but I put in some code that writes the result to a log file when the method fires off.
    I noticed that when I clicked on the button on the form, the error message would pop up from Acrobat, but when I check the log file, there was NO entry. This means that Acrobat failed before it could execute the method.
    Here is the web method:
    [WebMethod(CacheDuration = 30,
    Description="Returns the String 'True' or 'False' whether or
    not you entered a 'T' or 't'.")]
    public string TF(string Tf)
    string result="False";
    if(Tf.Substring(0,1).ToLower()=="t"){
    result= "True";}
    LogFile.Write("Sent: "+result);
    return result;

  • How to read text file line by line...?

    how to read text file line by line, but the linefeed is defined by user, return list of string, each line of file is a item of list?
    please help me.
    Thanks very much

    Brynjar wrote:
    In Groovy, you would do something like:
    linefeed = "\n" //or "\r\n" if the user chose so
    lines = new File('pathtofile').text.split("${linefeed}")This is one of the things that has always annoyed me about Sun's sdk, i.e. the lack of easy ways to do things like that. You always end up making your own utilities or use something like Apache's commons.io. Same goes for jdbc and xml - I'll wait for appropriate topics to show how easy that is in Groovy :)I generally agree, but what I really don't like about the Groovy text-file handling niceties: They don't care about encoding/always use the default encoding. And as soon as you want to specify the encoding, it gets a lot more complex (granted, it's still easier than in Java).

  • My file has insert command and i want to read that file line by line in sql

    myfile.txt
    insert into emp values(100,200,"sumedh",11);
    insert into emp values(101,200,"amit",11);
    insert into emp values(102,200,"sam",11);
    insert into emp values(103,200,"ram",11);
    insert into emp values(104,200,"stev",11);
    I want to read this file line by line and enter this value in emp table.

    Why did you begin this thread in security.
    just like
    sqlplus <schema_owner>/<password>@<your_sid> @<path_to/myfile.txt>

  • Reading a file line by line and executing the code

    I need to read a file line by line and execute them simultaneously.
    I use BufferedReader for reading , but for executing i tried a lot , but could not find a solution.
    Kindly help and try to brief me.

    If you're hoping to execute lines of java source code on the fly...then forget it. Java is a compiled language. It doesn't have an "eval" statement like other languages.
    Now, you can write an interpreter for a language in Java. And I suppose you could write an interpreter for Java in Java (although at that point, you might as well choose to interpret a different language; it would probably be easier). But that would be a pretty big task.

Maybe you are looking for

  • Is it possible to launch a form from an OAF page using OAF Personalization

    In R11, the Customer Standard form ARXCUDCI was customized to call a custom block from the Address screen. In R12 the customer standard form has become an OAF page. We have decided to create a custom form for the custom block using Oracle Developer.

  • How do I reset my ID password? Why is it visible in the box when I type it?

    i Had an email saying someone had used my ID on another device to purchase something. It is probably spam but I decided to reset my password ( not by following the email links.) In the box there was no ' starring' for security but I went ahead and ty

  • Tags: PSE6 versus Windows Live Photo Gallery

    Hi, I'm a Photoshop Elements 6 user who's mostly please with the program. I've avoided the organizer because tags assigned there don't seem to show up in Windows or Live photo gallery. Does anyone know if this has been fixed for PSE8? I am interested

  • Currency symbol in front of value

    In the Lead screen - for Potential Volume (currency type), in our case we enter the value (f.e 5000) and it is shown as 5000 R$, meaning our currency symbol...after the value. Would it be possible to change this format...and show the currency symbol

  • Bluetooth poor since Yosemite

    Since changing to Yosemite my Bluetooth speaker is experiencing interference similar to that of playing music on vinyl with a nasty scratch on it. I use iTunes Match on a 2011 iMac. I don't get the same interference when my iPad is linked by Bluetoot