Printing the First 14 Characters of Every Line in a Text File

My text file looks like the following:
1111097116274, H0101C58F8110C005, 1, 16:48:03
1111097116274, H0100058F8110C006, 2, 16:48:10
1111097116274, H00F0458F8110C006, 3, 16:48:12I want my java program to print the first 14 characters of every line. Here's what I have:
import java.awt.*;
import javax.swing.JOptionPane;
import java.io.*;
public class Read {
     public static void main( String args[] ) {
    try {
        BufferedReader in = new BufferedReader(new FileReader("aFile.txt"));
        String line;;
        /*String tagid;*/
        while ((line = in.readLine()) != null) {
             char[] tagid = line.toCharArray();
             line.getChars(0, 14, tagid, 0); 
             System.out.println(tagid);
        in.close();
    } catch (IOException e) {
         JOptionPane.showMessageDialog( null, "Error" );
         System.exit(0);
     Instead of printing the first 14 characters of every line to output, it prints the whole text file.
Any ideas of what's wrong?
Thanks.

Well, that's the thing with a highly tuned, precision engine like your mind, JosAH. Adding a little alchohol to the fuel mix provides a performance boost, but as the alcohol/fuel ration increases, the performance improvement peaks and then degrades, until the performance is actually reduced. Now, I understand that in the case of the magic Grolsch, this performance curve is shifted farther to the right (graphed with Grolsch count as the independent variable, and performance improvement as the dependent variable), but it still occurs.
I recommend nitrous oxide. You may need to get your piston heads hardened, though.
� {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Read the first word of each line in a text file

    i need to read the first word of each line of a text file.
    i know of line.split() but not actually sure how i would go about using it
    Any help most appreciated
    Many Thanks
    Ben

    Hi thanks for the reply!
    this is what i tried... and it still doesn't get me the first word of each line!
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.io.*;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import java.util.Calendar;
    import java.util.Scanner;
    import java.util.Vector;
    import java.text.SimpleDateFormat;
    import java.net.InetAddress;
    import java.net.UnknownHostException;
    import java.io.BufferedReader;
    public class testing {
         Vector progs=new Vector();
         Vector rand=new Vector();
         String[] tmp = new String [2];
         String str;
         String str2="ewerwer";
         String str3;
         public void programTest()
                   try
                             BufferedReader in = new BufferedReader(new FileReader("progList.log"));
                             while ((str = in.readLine()) != null)
                                  progs.add(str);
                        catch(IOException e)
                             System.out.println("cannot read file");
         //////THE ISSUES IS HERE....I WANT TO GET THE FIRST WORD FROM EACH LINE OF THE FILE!!!     
              try
                             BufferedReader in2 = new BufferedReader(new FileReader("eventLog.log"));
                             while ((str = in2.readLine()) != null)
                                  tmp = str.split(" ");
                                  System.out.println(tmp[0]);
                        catch(IOException e)
                             System.out.println("cannot read file");
    public static void main(String[] args)
                 testing B = new testing();
                 B.programTest();
               //  B.fileToVector();
                 //B.LoginWindow();
               //B.anomDetect();
    }//end class

  • How to read every line from a text file???

    How can i read every line from my text file ("eka.txt")
    now it only reads the first line and prints it out.
    What is wrong with this?
    import java.io.*;
    import java.util.*;
    class Testi{
         public static void main(String []args)throws IOException {
         BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    File inputFile = new File ("eka.txt");
    FileReader fis =new FileReader(inputFile);
    BufferedReader bis = new BufferedReader(fis);
    String test=bis.readLine();
    String tmp= "";
    while((bis.readLine().trim() != null)) {
    int spacefound=0;
    int l=test.indexOf(" ");
         for(int i=0;i<test.length();i++){
         char c=test.charAt(i);
         if(c!=' ') tmp+=""+c;
         if(c==' ' && (spacefound<1) && !(tmp.equals(""))){
         tmp+=""+c;
         spacefound++;
         if(tmp.length()==l) {
         System.out.println(tmp);
         tmp="";
         spacefound=0;
         if(tmp.length()<l){
         for(int i=0;i<=(l-tmp.length());i++)
         tmp+=""+' ';
         System.out.println(tmp);

    Try this code, Hope it servers your purpose.
    import java.io.*;
    import java.util.*;
    class Testi {
         public static void main(String []args)throws IOException {
              BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
              File inputFile = new File ("Eka.txt");
              FileReader fis =new FileReader(inputFile);
              BufferedReader bis = new BufferedReader(fis);
              String test=bis.readLine();
              while(test != null) {
                   StringTokenizer st = new StringTokenizer(test," ");
                   while(st.hasMoreTokens())
                        System.out.println(st.nextToken());
                   test = bis.readLine();
    }Sudha

  • Select first word in each line of a text file to do something.

    How do I select the first word in each line to do something newer from a text file in Powershell?
    Example:
     GBL                            Primary    File            
     local                          Primary    File            
     localhost                      Primary    File            
     Opstest                        Primary    File            
     TrustAnchors                   Primary    File            
    99upgrade

    Hi 99,
    here's an example on how to do it:
    $lines = Get-Content "C:\ExampleFolder\Example.txt"
    foreach ($line in $lines)
    Write-Host ($line.Split(" "))[0]
    Just replace the Write-Host line in the loop with what you actually want to do with the first word in the line.
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • How to add an space for every line in a text file in 46.B?

    Hi Friends!!
    My problem is the following,
    I need to add spaces in all lines of a text file
    Ej.'ABC ' , I'm using GUI_DOWNLOAD to download the internal table, but the function truncates all spaces, as it is 46B doesn't have the option for allowing the spaces at the end of each line,
    Do you know what can I do?? is there any other function module I could use?? I also tried with WS_DOWNLOAD but it didn't help!
    Thanks so much in advance!!!
    Frinee

    This a short example:
    data: begin of mytable occurs 0,
            line(2),
            lspace type x value '20',
            lenter type x value '0D0A',
          end of mytable.
    mytable-line = '1'.
    condense mytable-line.
    append mytable.
    mytable-line = '2'.
    condense mytable-line.
    append mytable.
    mytable-line = '3'.
    condense mytable-line.
    append mytable.
    call function 'GUI_DOWNLOAD'
         EXPORTING
           BIN_FILESIZE = 50
            FILENAME = 'C:\mybinfile.txt'
            FILETYPE = 'BIN'
         TABLES
            DATA_TAB = mytable
         EXCEPTIONS
           others = 9.

  • I don't want the first letter of every line to be capitalized

    When I try to put in user id's and passwords on web sites, I don't always want the first letter to be capitalized.  How do you make the Ipad stop doing this?

    Settings -> General -> Keyboard
    Turn off Auto-Capitalization.
    Regards.

  • D110 only prints the first line.

    If I send an item to the printer, it only prints the title. I have tried to copy to notepad and pasted to an email. Then sent it to the printer thru an email. It only prints the first line. How do I get it to print the whole item?

    You can use one of our diagnostic tool and can this can help you resolve the issue automatically and you can use it in future as well.
    http://h10025.www1.hp.com/ewfrf/wc/softwareCategory?os=4132&lc=en&cc=sg&dlc=en&sw_lang=&product=5169...
    Check if the issue gets resolved.
    Say "Thanks" by clicking the Kudos Star in the post that helped you.
    Please mark the post that solves your problem as "Accepted Solution"
    (Although I am employed by HP, I am speaking for myself and not for HP)

  • How to Capitalize the First Letter in Every Word in Mysql

    Hi,
    I have been trying to tidy up a massive database where visitors have been sloppy when entering text. The main thing I want to do is to Capitalize The First Letter In Every Word In Mysql.
    I have found the code below in PHP but it keeps finding an error on the WHILE line:
    <?php ini_set('display_errors', '1'); ?>
    <?php require_once('Connections/maison_connection.php'); ?>
    <?php
    $result = mysql_query ("SELECT column, id FROM table");
    while ($row = mysql_fetch_array($result)) {
    $id = $row["id"];
    $column2 = ucwords($row["column"]);
    $query2 = "UPDATE table SET column = '$column2′ WHERE id = '$id'";
    mysql_query($query2);
    ?>
    My table is called MailingList and the Column is called Name, so I have altered the script to this: but it still shows the same WHILE error:
    <?php ini_set('display_errors', '1'); ?>
    <?php require_once('Connections/maison_connection.php'); ?>
    <?php
    $result = mysql_query ("SELECT Name, id FROM MailingList");
    while ($row = mysql_fetch_array($result)) {
    $id = $row["id"];
    $Name2 = ucwords($row["Name"]);
    $query2 = "UPDATE MailingList SET Name = '$Name2′ WHERE id = '$id'";
    mysql_query($query2);
    ?>
    Any ideas??

    I got it to work this way in SQL: I am SURE there is an abbreviated way to do it, but at least it works
    UPDATE MailingList SET Name = replace(Name," a"," A");
    UPDATE MailingList SET Name = replace(Name," b"," B");
    UPDATE MailingList SET Name = replace(Name," c"," C");
    UPDATE MailingList SET Name = replace(Name," d"," D");
    UPDATE MailingList SET Name = replace(Name," e"," E");
    UPDATE MailingList SET Name = replace(Name," f"," F");
    UPDATE MailingList SET Name = replace(Name," g"," G");
    UPDATE MailingList SET Name = replace(Name," h"," H");
    UPDATE MailingList SET Name = replace(Name," i"," I");
    UPDATE MailingList SET Name = replace(Name," j"," J");
    UPDATE MailingList SET Name = replace(Name," k"," K");
    UPDATE MailingList SET Name = replace(Name," l"," L");
    UPDATE MailingList SET Name = replace(Name," m"," M");
    UPDATE MailingList SET Name = replace(Name," n"," N");
    UPDATE MailingList SET Name = replace(Name," o"," O");
    UPDATE MailingList SET Name = replace(Name," p"," P");
    UPDATE MailingList SET Name = replace(Name," q"," Q");
    UPDATE MailingList SET Name = replace(Name," r"," R");
    UPDATE MailingList SET Name = replace(Name," s"," S");
    UPDATE MailingList SET Name = replace(Name," t"," T");
    UPDATE MailingList SET Name = replace(Name," u"," U");
    UPDATE MailingList SET Name = replace(Name," v"," V");
    UPDATE MailingList SET Name = replace(Name," w"," W");
    UPDATE MailingList SET Name = replace(Name," x"," X");
    UPDATE MailingList SET Name = replace(Name," y"," Y");
    UPDATE MailingList SET Name = replace(Name," z"," Z");

  • Making the first letter of every word a capital

    hello CF oracles
    could you guys please advise me the best way to make the
    first letter in every word of a string a capital letter. (and make
    all the other letters lower case).
    eg. convert "the quick brown fox" into "The Quick Brown Fox"
    or convert "THE QUICK BROWN FOX" into "The Quick Brown Fox"
    I am taking form data and inserting it into my table, so i
    want to get it right as the data is inserted.
    i found a "UDF" on CFLIb.org that proports to do this, but i
    don't know how to set up a UDF, are there other ways or is this
    considered the best approach.
    http://www.cflib.org/udf.cfm?id=9&enable=1
    thanks for any help you can give me

    found it, here's the top info, Titlecase is what you want for
    this.:
    changecase.cfm
    Rev 1.01
    cf_changecase is a simple custom tag to format case in given
    string.
    (c) 2001, Rizal Firmansyah, [email protected]
    Input var:
    * case (mandatory)
    possible inputs are
    - sentencecase: Sentence case (default)
    - titlecase: Title Case
    - lowercase: lowercase
    - uppercase: UPPER CASE
    "happysailingdude" <[email protected]> wrote
    in message
    news:e46tjv$e30$[email protected]..
    > hi Dan thanks very much. I have made an executive
    decision to do a bit of
    > a
    > hack for now as my site is only small so if a user
    enters something in the
    > wrong way i can quickly manually update it myself.
    >
    > so now i have this which works 9 times out of ten if the
    user enters a one
    > word name eg "bill" or "fred" of "jane" then it works
    just fine
    >
    > the only time it doesnt work is if the user's name is
    more than 1 word (or
    > is
    > hyphenated) eg "mary anne" or "anne-marie" hence the
    first cfif line - in
    > these
    > cases i can manually update
    >
    > i put this here in case it is of use to anyone else
    >
    > cheers
    >
    > <cfif not (FORM.firstName contains " " or
    FORM.firstname contains "-")>
    > '#Left( UCase( "#FORM.firstName#" ), 1 )##Right( LCase(
    > "#FORM.firstName#" ), Len("#FORM.firstName#" ) - 1 )#'
    > <cfelse>
    > '#FORM.firstName#'
    > </cfif>
    >

  • Firefox 3.6.6 only prints the first page on windows 2000

    Trying to print web pages using forefox 3.6.6 on Windows 2000 only the first page prints though multiple blank pages are printed after the first
    == This happened ==
    Every time Firefox opened
    == don't know but noticed with 3.5

    They gotta fix this. It's been a huge problem for me for more than a year. I''ll defect to Chrome soon if they dont address this bug soon. Printing has been atrocious, even pathetic, i hate to say it. I can only print one page, maybe two if i am lucky. Sometimes, if it prints more than one page, the first page is mostly blank and the formatting of the text and sidebars is completely overlapped and sometimes unreadable. Basically, printing in Firefox is useless - it's a joke. I have to take the URL from Firefox and paste it into Chrome to get a decent print job. Why isnt this bug a higher priority?
    Tags: Firefox cannot print, Firefox printing bug, Firefox only prints one page

  • I want to print an email which has multi pages but I can only print the first page

    Can anyone help please?
    i want to print an email which has multi pages but I can only print the first page
    Tony

    Firefox cuts off the URL in your printout, if it's really long, and you also have on the same line (header or footer), the Date and Pages
    What I have summarized below is based on this page . . . http://www.watchingthenet.com/how-to-change-or-customize-firefox-printing-defaults.html
    I have two questions:
    To fix, do a custom setting, for the Header and Footer as follows:
    Print / Page Setup / Margins & Header/Footer / "Customize" the "Left" as follows (leave Center and Right all blank)
    &T
    &U . . . . . . . &D . . . . . . . &PT
    &D shows the Short date as: M/d/yyyy - and then the time
    To change the format of the Short date in Win 8.1, go to:
    Control Panel / Date and Time / Date and Time tab / Change date and time / Change calendar settings /
    Date / Short date . . . change from M/d/yyyy . . . to . . . MM/dd/yy
    QUESTIONS:
    1.) How do you get rid of the time, which appears after the date? In IE, you use a lowercase "d" - but that doesn't work here.
    2.) Is there a way to change the font just for the Header and Footer, to something like Microsoft Sans Serif 10?
    Firefox leaves no room around the text in the Header and Footer at the edge. To fix:
    Address Bar / about:config
    Enter keyword "edge"
    Then change all four values for the printer you're using to:
    print.printer_Foxit_PhantomPDF_Printer.print_edge_bottom . . . 5
    print.printer_Foxit_PhantomPDF_Printer.print_edge_left . . . 10
    print.printer_Foxit_PhantomPDF_Printer.print_edge_right . . . 10
    print.printer_Foxit_PhantomPDF_Printer.print_edge_top . . . 5

  • Printer only prints the top half of some lines

    The printer prints only the top half of some lines while printing at faster speeds. Some documents I try to print will only print at a faster speed and I don't know how to slow it down

    Hello fishinbob,
    Welcome to the HP Forums!
    I understand your printer only prints the top half of some lines. I will do my best to assist you! First, I would like to ask you a couple of questions:
    What type of printer do you have? Click here to find out: Model Number.
    What is your operating system on your computer? Windows or Mac?
    Please verify this information and I will assist you further. Have a great day!
    I worked on behalf of HP.

  • My problem is that after printing the first photo or picture, when I come to print a second, both the Colour Management and Epson Colour Controls are greyed out and showing No Colour Management

    I have recently purchased a Mac computer (updated to Maverick) to go with my Epson Stylus Photo RX500 printer which has given excellent service with my old Windows computer. However, when trying to print pictures or photos via Photoshop Elements 11, the best results I can get are using the Colour Management and Epson Colour controls in the printing options box.
    My problem is that after printing the first photo or picture, when I come to print a second, both the Colour Management and Epson Colour Controls are greyed out and showing No Colour Management, The only way I can reset the controls is to shut down the printer and computer and restart.
    Could there may be a setting somewhere that I need to adjust please?  I have been in touch with Epson and they say that the Epson Colour controls are part of the Photoshop Elements software but a post on the Adobe forum brought no results and I am unable to contact Adobe.
    <Edited by Host>

    Hello Garry. Thanks for the reply. I guess I should have used a different title from "How do I post a question?" That should come after trying to resolved the colour settings first. However, to answer your question, after experimenting with all the different settings in Photoshop Elements and Epson software, I now start with PSE11 Colour settings then click "no colour management" then after clicking Print, I choose "More Options/Colour Management/Colour Handling/Printer Manages Colour" then I choose "Page Setup/Layout/Colour Matching" which then shows Epson Colour Controls but I also choose "Layout/Colour Management" which then shows "Colour Controls/Mode" I then of course choose an Epson printer profile depending on the paper I am using. I get good results but as I said, the Colour Matching and Colour Controls are then greyed out. Hope that makes sense.

  • How do I create a calendar event for the first Sunday of every moth?

    Trying to create an event on my iPhone 4 (iOS 5) calendar that repeats on the first Sunday of every month.  Is there a way to do this?
    Thanks

    JohnnyDawg wrote:
    Hopefully we will get full iCal functionality on the iPhones and iPads one day.
    It would be nice, but don't hold your breath. But look at 3rd party calendar apps such as Week Cal or Pocket Informant.

  • How do I print the first page of numerous documents?

    Computer setup:
    Adobe Acrobat Pro 9.10 on Windows XP Professional x64 Edition.
    User experience:
    I consider myself proficient in office (Excel, Word) and software use in general (Windows XP). The extent of my Adobe Acrobat experience is creating custom dynamic stamps. I have little to no javascript programming knowledge.
    Problem:
    Numerous pdf files in multiple directory locations must have the first page of each document printed.
    Current (and time-consuming) solution:
    Copy the files to a single directory
    Use Acrobat Pro to combine files and individually select the first page for each document
    Combine and print.
    Tools
    Filename Extractor (can be used to extract the filename OR filename and path of documents)
    Bonus Points
    An index of all documents exists in Excel format. Documents are selected for printing by filtering this Excel index. The Excel index will have a column containing the path of each document. A solution that can utilise this path information to shortcut the time-consuming "copy and paste" method currently used will attract bonus points.
    Thanks in advance,
    Simon

    Create a batch process the executes the following JavaScript code:
    this.print({nStart:0, bUI: false, bSilent: true});
    It will silently print the first page of any file you batch. Be careful not to overload your printer's queue by sending too many files in one go.

Maybe you are looking for

  • Where to look for all value mappings being used in ID

    Hi All,           Where to look for all value mappings being used in ID? XIer

  • Daisy chaining two Lacie Firewire 800 drives on a G%

    I've had one external drive working perfectly for months. Tried to daisy chain a second drive and can't get the second drive to register on my desktop. Support said to reboot. My system freezes upon shutting down. If I restart with the two connected,

  • OBPM contract opportunity

    HI, I'm currently seeking an OBPM developer for a client based in Denmark for a 6 month contract. If you would like to gain some more information could you please contact me ASAP. The developer will have a strong Oracle BPM, Java and JEE background a

  • Inconsistency with import workflow

    Hello gentlemen and ladies, as well as Apple Community friends, For past consecutive, straight days of trying to import AVCHD (.mts native files) from Canon VIXIA HF S21 HD CMOS camcorder, believe me, I have try all possible solution to import throug

  • Latest Flash Player Wont Install

    I can NOT seem to get flash installed on my computer. I went to download the current version and I am getting this error "The installation encountered errors: No error information is available." I am running Windows 7 Professional 64 bit. I get this