How to read the last line in a text file using text_io?? please help

Dear all
I made a procedure that append text into a text file on the operating system.
the text file grows rapidly. It contains now about 200,000 line . I need to read the last line only . In other wprds i need to go direct to the last line to read some values. Is it possible??
Please help

Hello,
If you know the number of the line you want to read, I can sugget you to use the MORE dos command or the TAIL unix command that redirect to a temporary text file
Example to create a file that contains the 200010th last lines :
(Client)Host( 'MORE the_file_name.txt +200010 > small_file.txt') ;So you have only to read the small file with the TEXT_IO functions.
Francois

Similar Messages

  • How to read the last line in a txt file?

    Dear all,
    I want to read the last line in a txt file. There are thousands of lines in this file. What I want is to move the file pointer directly to the last line of the file. But I did not know how do to it. Can anybody help me out?
    Thank you very much!

    If the file is coded as ASCII or one of the encodings that maps a single byte to a char then the following class will assist you
    import java.io.*;
    import java.util.*;
    public class GetLinesFromEndOfFile
        static public class BackwardsFileInputStream extends InputStream
            public BackwardsFileInputStream(File file) throws IOException
                assert (file != null) && file.exists() && file.isFile() && file.canRead();
                raf = new RandomAccessFile(file, "r");
                currentPositionInFile = raf.length();
                currentPositionInBuffer = 0;
            public int read() throws IOException
                if (currentPositionInFile <= 0)
                    return -1;
                if (--currentPositionInBuffer < 0)
                    currentPositionInBuffer = buffer.length;
                    long startOfBlock = currentPositionInFile - buffer.length;
                    if (startOfBlock < 0)
                        currentPositionInBuffer = buffer.length + (int)startOfBlock;
                        startOfBlock = 0;
                    raf.seek(startOfBlock);
                    raf.readFully(buffer, 0, currentPositionInBuffer);
                    return read();
                currentPositionInFile--;
                return buffer[currentPositionInBuffer];
            public void close() throws IOException
                raf.close();
            private final byte[] buffer = new byte[4096];
            private final RandomAccessFile raf;
            private long currentPositionInFile;
            private int currentPositionInBuffer;
        public static List<String> head(File file, int numberOfLinesToRead) throws IOException
            return head(file, "ISO-8859-1" , numberOfLinesToRead);
        public static List<String> head(File file, String encoding, int numberOfLinesToRead) throws IOException
            assert (file != null) && file.exists() && file.isFile() && file.canRead();
            assert numberOfLinesToRead > 0;
            assert encoding != null;
            LinkedList<String> lines = new LinkedList<String>();
            BufferedReader reader= new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
            for (String line = null; (numberOfLinesToRead-- > 0) && (line = reader.readLine()) != null;)
                lines.addLast(line);
            reader.close();
            return lines;
        public static List<String> tail(File file, int numberOfLinesToRead) throws IOException
            return tail(file, "ISO-8859-1" , numberOfLinesToRead);
        public static List<String> tail(File file, String encoding, int numberOfLinesToRead) throws IOException
            assert (file != null) && file.exists() && file.isFile() && file.canRead();
            assert numberOfLinesToRead > 0;
            assert (encoding != null) && encoding.matches("(?i)(iso-8859|ascii|us-ascii).*");
            LinkedList<String> lines = new LinkedList<String>();
            BufferedReader reader= new BufferedReader(new InputStreamReader(new BackwardsFileInputStream(file), encoding));
            for (String line = null; (numberOfLinesToRead-- > 0) && (line = reader.readLine()) != null;)
                // Reverse the order of the characters in the string
                char[] chars = line.toCharArray();
                for (int j = 0, k = chars.length - 1; j < k ; j++, k--)
                    char temp = chars[j];
                    chars[j] = chars[k];
                    chars[k]= temp;
                lines.addFirst(new String(chars));
            reader.close();
            return lines;
        public static void main(String[] args)
            try
                File file = new File("/usr/share/dict/words");
                int n = 10;
                    System.out.println("Head of " + file);
                    int index = 0;
                    for (String line : head(file, n))
                        System.out.println(++index + "\t[" + line + "]");
                    System.out.println("Tail of " + file);
                    int index = 0;
                    for (String line : tail(file, "us-ascii", n))
                        System.out.println(++index + "\t[" + line + "]");
            catch (Exception e)
                e.printStackTrace();
    }Note, the EOL characters are treated as line separators so you will probably need to read the last two lines (think about it for a bit).

  • How to read the second line in a .txt file with bufferedReader?

    hi,
    i am not the best in speaking english and programming java :)
    so, just try to make sense of my question:
    Im using a BufferedReader to read a .txt file.
    the .txt file has 5+ different lines, and each line has 6 tokens (separated with ; )
    My java file has 6 textFields and each textfield is filled with one of the 6 different tokens.
    and my problem is:
    I want my buffered reader to read the next line (with 6 new different tokens) by pressing a button.
    if somethings not understandable, just ask :)

    maybe its easier to help me, when i publish my code, so here it is:
    (its my version, without Thof's code. Sorry, but the comments are the most in german)
    /* userdata.java */
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    public class userdata extends Frame {
    //-----------------------------------KlassenVariablen------------------------------------------------
    private JPanel panel = new JPanel ();
    String tokId = "";
    String tokName= "";
    String tokAge= "";
    String tokTel= "";
    String tokMail= "";
    String tokText= "";
    BufferedReader br;
    String zeile;
    StringTokenizer st;
    String delim = ";";
    //---------Buttons f?r Panel 1-------------------------
    Button first = new Button("|< First");
    Button back = new Button("< Back");
    Button next = new Button("Next >");
    Button last = new Button("Last >|");
    //---------Buttons f?r Panel 3-------------------------
    Button neu = new Button("New");
    Button safe = new Button("Safe");
    Button refresh = new Button("Refresh");
    //--------Labels f?r Panel 2-----------------------------
    Label lid = new Label("ID",Label.LEFT);
    Label lname = new Label("Name",Label.LEFT);
    Label lage = new Label("Age",Label.LEFT);
    Label ltel = new Label("Tel.",Label.LEFT);
    Label lmail = new Label("E-Mail",Label.LEFT);
    Label ltext = new Label("Spruch",Label.LEFT);
    Label lub = new Label("Last Button",Label.LEFT);
    TextField id = new TextField();
    TextField name = new TextField();
    TextField age = new TextField();
    TextField tel = new TextField();
    TextField mail = new TextField();
    TextField text = new TextField();
    TextField usedbutton = new TextField();
    //--------ActionEvent bla sachen eben--------------------
    public static void main (String[] args) throws IOException {
    userdata wnd = new userdata();
    wnd.setVisible(true);
    public userdata() throws IOException {                                                                                                                                                                                                                                                                                
    //--------------------------------Layout mit panel bestimmung--------------------------------------
    setLayout(new BorderLayout());
    JPanel p1 = new JPanel();
    JPanel p2 = new JPanel();
    JPanel p3 = new JPanel();
    add(BorderLayout.NORTH ,p1);
    add(BorderLayout.CENTER , p2);
    add(BorderLayout.SOUTH , p3);
    //-------------------------------Funktionslose Buttons in PANEL 1------------------------------------
    p1.add(first);
    p1.add(back);
    p1.add(next);
    p1.add(last);
    p1.add(usedbutton);
    //--------------------------------Funktionierende Textfelder in PANEL 2------------------------------
    Panel labelpanel = new Panel();
    p2.setLayout(new GridLayout(7,3));
    p2.add(lid);
    p2.add(id);
    p2.add(lname);
    p2.add(name);
    p2.add(lage);
    p2.add(age);
    p2.add(ltel);
    p2.add(tel);
    p2.add(lmail);
    p2.add(mail);
    p2.add(ltext);
    p2.add(text);
    p2.add(lub);
    p2.add(usedbutton);
    //--------------------------------------Buttons in PANEL 3-----------------------------------------
    p3.add(neu);
    p3.add(safe);
    p3.add(refresh);
    //--------------------------------BufferedReader -------------------------------------------------
    readData();
    //--------------------------------Panel 2 TextField-----------------------------------------------
    fillForm();
    //================================ActionPerformed==================================================
    first.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("First");
    usedbutton.setText("First");
    back.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Back");
    usedbutton.setText("Back");
    next.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Next");
    usedbutton.setText("Next");
    last.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Last");
    usedbutton.setText("Last");
    neu.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("New entry");
    usedbutton.setText("New");
    safe.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Now Saving, do not turn off!");
    usedbutton.setText("Save");
    //-----------------refresh
    refresh.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    try{
    readData();
    }catch( IOException ioe){
    System.out.println("Fehler beim lesen aus Datei");
    fillForm();
    usedbutton.setText("Refresh");
    //=============================================================================Button Funktionen!!!
    pack();
    //--------------------------------WindowsListener hinzuf?gene--------------------------------------
    addWindowListener(
    new WindowAdapter() {
    public void windowClosing(WindowEvent event)
    setVisible(false);
    dispose();
    System.exit(0);
    //-----------------------------------readData() - > Buffered Reader in aktion! --------------------
    private void readData() throws IOException{
    BufferedReader br = new BufferedReader(new FileReader("My .txt File with path"));
    String zeile;
    StringTokenizer st;
    String delim = ";";
    zeile = br.readLine();
    st = new StringTokenizer(zeile, delim);
    st.hasMoreTokens();
    //System.out.println (st.nextToken());
    tokId = new String(st.nextToken());
    tokName = new String (st.nextToken());
    tokAge = new String (st.nextToken());
    tokTel = new String (st.nextToken());
    tokMail = new String (st.nextToken());
    tokText = new String (st.nextToken());
    //--------------------------fillForm() - > f?llt die TextFelder aus!--------------------------------
    private void fillForm(){
    id.setText(tokId);
    name.setText(tokName);
    age.setText(tokAge);
    tel.setText(tokTel);
    mail.setText(tokMail);
    text.setText(tokText);
    }

  • How to edit/modify a line of a text file using java io

    Hi every body
    I am new 2 java
    I am struck in editing a text file that ends with .dat
    I successfully added,viewed data of the *.dat file.
    but,I cannt edit,delete the lines that i need to do randomly.
    Here is the code i have written.
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.LineNumberReader;
    import java.io.RandomAccessFile;
    import java.util.ArrayList;
    import java.util.StringTokenizer;
    public class ReadWriteFile {
         String id=null;
         String name=null;
         String dept=null;
         String doj=null;
         String adrss=null;
         public void WriteFile(String Id,String Name,String Dept,String Doj,String Adrss) throws IOException{
              File f=new File("TraineeDetails.dat");
             if(!f.exists()){
             f.createNewFile();
              BufferedWriter bw=new BufferedWriter(new FileWriter("TraineeDetails.dat",true));
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
              System.out.print("Enter Id : ");
              Id=br.readLine();
              System.out.print("Enter name : ");
              Name=br.readLine();
              System.out.print("Enter dept : ");
              Dept=br.readLine();
              System.out.print("Enter doj : ");
              Doj=br.readLine();
              System.out.print("Enter adrss : ");
              Adrss=br.readLine();
              bw.write(Id+"::"+Name+"::"+Dept+"::"+Doj+"::"+Adrss+":END:");
              bw.flush();
              bw.newLine();
              bw.close();
         public static void main(String[] args) throws IOException {
              ReadWriteFile rwf=new ReadWriteFile();
              String TID = null;
              String TADRSS = null;
              String TDOJ = null;
              String TNAME = null;
              String TDEPT = null;
              rwf.ReadFile(TID,TNAME,TDEPT,TDOJ,TADRSS);
         public void ReadFile(String Id1,String Name1,String Dept1,String Doj1,String Adrss1) throws IOException{
              BufferedReader br = new BufferedReader(new FileReader("TraineeDetails.dat"));
              String s;
               while((s = br.readLine())!= null)
                 // Create string tokenizer
                    StringTokenizer st =new StringTokenizer(s, "::");
                      System.out.println("----------------------------------------------");
                      System.out.println("| Trainee Id: "+st.nextToken()             +"|");
                      System.out.println("| Trainee Name: "+st.nextToken()           +"|");
                      System.out.println("| Trainee Department:"+st.nextToken()      +"|");
                      System.out.println("| Date of Joining: "+st.nextToken()        +"|");
                      System.out.println("| Trainee Address: "+st.nextToken()        +"|\n");
                      System.out.println("----------------------------------------------");
               // Close file reader
               br.close();
    }     and here is the data i have written
    Trainee.dat*
    111::jain::roads::2-2008::Blore:END:
    123::tim::service::1-2000::delhi:END:
    444::faru::civil::3-2200::sanapur:END:
    555::niv::cse::10-2000::gnagar:END:
    999::linda::mech::6-2001::tnagar:END:
    258::yansi::geo::8-2002::rtnagar:END:
    656::hari::garrage::3-1000::uttarahalli:END:
    888::muni::hr::5-2009::ernakulam:END:
    007::bond::spy::2-1972::america:END:
    0123::landy::games::6-2003::hdp:END:
    678::maddy::pumbing::4-1999::dispur:END:

    kalanidhi2u wrote:
    I want to randomly access the file
    But i cannt access itmake it RandomAccessFile... RandomAccessFile
    I edited it
    but i cannt edit the file by using itBoth of these are contradictory.

  • How to only read the last line in the text file by using BufferedReader ?

    Dear all,
    Hello, I am new to Java. Do anybody know how to read the last line (this is the last record) in the text file.The method I am now using is reading from the first line until I reach the last line in the text file. Thank you!!
    BufferedReader br = new BufferedReader(new FileReader("c:\\sdk1.4.1\\bin\\dbExport.txt"));
    DataInputStream in = new DataInputStream(new FileInputStream("c:\\sdk1.4.1\\bin\\dbExport.txt"));
    String input;
    String firstinput;
    String secondinput;
    int count=90;
    int year=1955;
    while ((input = br.readLine()) != null) {
    firstinput = input.substring(0, 10);
    secondinput = input.substring(10);
    String insertStore1 = ("INSERT INTO AUTHORS " +
    "VALUES ('" + count + "', '" + firstinput + "', '" + secondinput + "', 1955)");
    System.out.println(insertStore1);
    int result = stmt.executeUpdate(insertStore1);

    I suppose you could use a java.io.RandomAccessFile.

  • How to make the last line of the textarea visible all the time?

    Hello,
    I am making an online chat application in JSP and XHTML. The chat log and online users� names textareas are refreshed every 5 seconds. When it comes to many messages in the chat log textarea, the scrollbar appears. Then, every time the chat log textarea is refreshed, I need to move the scrollbar down to see the last line of the textarea.
    Are there any ideas how to make the last line of the textarea visible all the time without moving the scrollbar?
    Thanks in advance.
    Dan

    I put the below code on the page, but it didn't work.
    Are there any ideas? Thanks.
    <table border="0" cellspacing="1">
    <tr>
    <th>Chat Log</th>
    <th>Users now online</th>
    </tr>
    <tr>
    <td><textarea rows="20" cols="60" name = "messages" readonly = "readonly"><%= texts %></textarea></td>
    <td><textarea rows="20" cols="20" name = "names" readonly = "readonly"><%= names %></textarea></td>
    </tr>
    </table>
    <script type="text/javascript">
    <!--
    document.messages.scrollIntoView(false);
    //-->
    </script>

  • Can I align the last line of a text container to to bottom of a container?

    Is it possible to take the last line in a text container and vertically align it to the bottom? I'm aware that I can justify the entire text container vertically to achieve this effect. However, this means tha every line in the container is now spaced out with increased leading.
    Here's a screen capture of what I mean.
    On the right is a text container without any vertical justification and sized to fit the text. On the left is a text container that I've sized to match the height of the right container. In order to get the last line to align to the bottom I used the Justify vertically option. But my bullets are now spread out.
    Basically I just want the last line aligned to the bottom and the rest of the text above it to be aligned to the top.
    Is there anyway to do this with just one text container? Or will I be forced to used two text containers?
    I'm using InDesign CS5 if that matters.

    I think I'd do this with a two-cell table.

  • Read a specific line of a txt file using vba not using line by line, Leer una Linea especifica de archivo de texto sin recorrer linea por linea

    Buenos días - Good morning
    Mi pregunta la escribiré en español y en ingles y espero alguien tenga la solución.
    I'll write my question in Spanish and English and I hope someone has the solution.
    SPANISH
    Creé una Macro en VBA que lee mas de 200.000 archivos de texto (.txt) los cuales tienen diferentes tamaños y cantidad de información dentro de ellos, de cada archivo necesito extraer la información de las 3 primeras lineas y las ultimas 10 lineas, las 3
    primeras lineas es fácil ya que uso un "READLINE" 3 veces y voy capturando la información de las tres primeras lineas, para las ultimas 10 lineas las cuales están identificadas por un código inicial hago un ciclo que lee linea por linea hasta que
    encuentra el numero 3 en un espacio especificado de la linea y de ahí captura la información de cada linea de texto que serian las 10 ultimas, el problema que tengo es que la cantidad de archivos y de información dentro de los archivos aumenta considerablemente
    cada día y por tener el ciclo que lee cada una de las lineas de cada archivo de texto la Macro se demora cada vez mas a medida que aumenta la información y consume cada vez mas memoria de la maquina.
    Necesito un método diferente que no lea linea por linea y que yo le pueda decir lea la linea (renglón) numero 1000 (ejemplo) y capture la información a partir de ahí para ahorrar algo de tiempo, o saber cuantas lineas de texto tiene el archivo .txt y decirle
    que me lea a partir de (numero total de lineas del txt -(menos) 10 lineas) así me leería las 10 ultimas.
    ENGLISH
    I created a Macro in VBA that reads more than 200,000 text files (.txt) which have different sizes and quantity of information within them, each file need to extract the information from the first 3 lines and last 10 lines, 3 first lines is easy as using a
    'READLINE "3 times and am capturing information from the first three lines, for the last 10 lines which are identified by an initial code I make a loop that reads line by line until it finds the number 3 in a specified area of ​​the line and then capture
    the information of each line of text that would be 10 last, the problem that I have is that the number of files and information within files significantly increases every day and having the loop that reads each line of each text file is delayed Macro increasingly
    as more information and consume more and more memory on the machine.
    I Need a different method not read line by line and I can tell you read the line (row) number 1000 (example) and capture the information from there to save some time or know how many lines of text have the file .txt and tell me read from (total number of lines
    of txt - (minus) 10 lines) so I would read 10 last.
    Here is the code I currently use
    Dejo el código que uso actualmente
    Dim fs, f, ts, REG
    Set fso = CreateObject("Scripting.FileSystemObject")
        On Error Resume Next
    sFilePath = strFolder & "\" & strFileName
    Set f = fso.getFile(sFilePath)
    Set ts = f.OpenAsTextStream(1, 0)
    REG = ts.READLINE
    Ciclo para llegar hasta las ultimas 10 lineas
    Cycle to reach the last 10 lines
    For J = 1 To 200000
                REG = ts.READLINE
                    If Val(Mid(REG, 6, 1)) = 3 Then

    Good Morning ryguy72
    First thank you so much for your answer, sorry for my english in the question, I tried for a long time to make a code that wasn't so slow to read the last 10 lines, 'cuz most codes used a cycle "For" to read line by line asking if in the specific
    position is the character(number) that tells me that i should get started to read the last lines that i need, that takes a lot longer than your code doing a Split with Mydata and storing it in strData(). I don't know how to do this and every forum that
    i consulted to read the last 10 lines quickly they made the same read line by line with a Cycle "for".
    Thanks again, I gonna improve my code with your help, 'cuz it took about 4 hours to read all the information and everyday ascended more time and memory consumption.
    Thanks to everyone who offered their help so disinterested and free, so should always be people with that spirit, I hope someday to be SO good as you programming.

  • Best way to remove last line-feed in text file

    What is the best way to remove last line-feed in text file? (so that the last line of text is the last line, not a line-feed). The best I can come up with is: echo -n "$(cat file.txt)" > newfile.txt
    (as echo -n will remove all trailing newline characters)

    What is the best way to remove last line-feed in text file? (so that the last line of text is the last line, not a line-feed). The best I can come up with is: echo -n "$(cat file.txt)" > newfile.txt
    (as echo -n will remove all trailing newline characters)
    According to my experiments, you have removed all line terminators from the file, and replaced those between lines with a space.
    That is to say, you have turned a multi-line file into one long line with no line terminator.
    If that is what you want, and your files are not very big, then your echo statement might be all you need.
    If you need to deal with larger files, you could try using the 'tr' command, and something like
    tr '
    ' ' ' <file.txt >newfile.txt
    The only problem with this is, it will most likely give you a trailing space, as the last newline is going to be converted to a space. If that is not acceptable, then something else will have to be arranged.
    However, if you really want to maintain a multi-line file, but remove just the very last line terminator, that gets a bit more complicated. This might work for you:
    perl -ne '
    chomp;
    print "
    " if $n++ != 0;
    print;
    ' file.txt >newfile.txt
    You can use cat -e to see which lines have newlines, and you should see that the last line does not have a newline, but all the others still do.
    I guess if you really did mean to remove all newline characters and replace them with a space, except for the last line, then a modification of the above perl script would do that:
    perl -ne '
    chomp;
    print " " if $n++ != 0;
    print;
    ' file.txt >newfile.txt
    Am I even close to understanding what you are asking for?

  • How to display the out put of the sql query in a text file using forms

    I want to display the out put of the sql query in a text file using forms 6.0.Same could be done using spool command in sqlplus but i want it using forms....Fiaz

    Have a look at the text_io package:
    http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/oraini/c_text_io.html&vtTopicId=
    cheers

  • I cant't read the last line in the grid

    hello,
    I use a grid to display a SQL query with a field-entry
    When I loop through the grid, I manage to read all lines except the line or the cursor, it keeps the old value
    Do you have an idea
    Thank you

    It's my code
            Shared Sub ItemEvent_Maj_emplacement_lot(ByRef FormUID, ByRef pVal, ByRef BubbleEvent)
                Dim EventEnum As SAPbouiCOM.BoEventTypes
                EventEnum = pVal.EventType
                If pVal.ItemUID = "1" Then
                    Dim jj As Integer
                    EventEnum = pVal.EventType
                    If EventEnum = BoEventTypes.et_CLICK Then
                        oform = SBO_application.Forms.Item(FormUID)
                       oitem = oform.Items.Item("MyGrid")
                        oGrid = oitem.Specific
                        Dim ColNum = oGrid.Columns.Count
                        Dim OgridCodeItem As Long
                        Dim OgridCodeMag As String
                        Dim OgridCodeLot As String
                        Dim OgridEmplacement As String
                        If oGrid.Columns.Count = 0 Then
                            Exit Sub
                        End If
                        For jj = 0 To oGrid.Columns.Count
                            Try
                                OgridCodeItem = oGrid.DataTable.GetValue(1, jj)
                                OgridCodeMag = oGrid.DataTable.GetValue(2, jj)
                                OgridCodeLot = oGrid.DataTable.GetValue(3, jj)
                                OgridEmplacement = oGrid.DataTable.GetValue(5, jj)
      ' This field OgridEmplacement is This field keeps the old value only on the last line before
    ' On the other lines, it works well
                            Catch oEx As Exception
                                '                          MessageBox.Show(oEx.Message & " jj = " & CStr(jj))
                                ' Exit Sub
                            End Try
                        Next jj
                    End If
                End If
            End Sub

  • How to remove the last line input into a string indicator??

    I am currently working on a program where the user has the ability to create a profile for one of our lab machines to run.  When the user selects what parameters they would like, a string indicator shows the user the last input they set followed by a comma.  For example, if the user selects which profile they want, and the times they would like to set, the following string would be displayed:
    As you can see in the picture above, the profile is updated in the string indicator after every set button is hit.  In the event the user makes a mistake, I want them to have the ability to delete the last line that was added.
    This is the code I developed so far.  The string coming in and leaving is attached to a shift register so it continues to append to the indicator.  I tried in this case to count how many lines have been written in the string so far, and I built an array with the current string.  Using the delete from array.VI I indexed it to the number of lines that was created so that the last line is deleted.  I unfortunately had no luck.  Any suggestions?

    tbob wrote:
    Fonzie1104 wrote:
    Hey Tbob,
    That almost worked.  The only issue though is it leaves a null string in its place without moving everything after up one line.  Also, if i have a parameter repeating multiple times, it doenst seem to work.
    I'm confused.  If you are deleting the last line, how can there be anything after?  What do you mean by a parameter repeating multiple times?
    If you look at my example front panel, you will see that the last line is deleted.  Isn't this what you asked for?
    It's due to the fact that your constant doesn't have a comma in the last line. If you add that in, you should be able to reproduce his problem. This is just a guess though, I didn't actually test it to see.
    Message Edited by for(imstuck) on 06-08-2010 01:24 PM
    CLA, LabVIEW Versions 2010-2013

  • How to read a specific line of a .dat file?

    can we read a specific line of a .dat file, if so, how?
    i have this .dat files for each customer, which contain their name on the first line, their id on the second line
    and a list of items and an item id between each item.
    John Doe
    455689
    milk
    1
    orange
    9
    Here is what I am trying to do, please correct me
    //list out .dat file in dir
    File customer_dir = new File ("Customer")
    if (customer_dir.isDirectory())
    String[] listofdat=dir.list();
    for (int i=0;i<listofdat.length();i++)
    Scanner dat_read = new Scanner (new File listfodat);
    dat_read.nextLine();
    if (dat_read.nextLine().equals("455689")) <--is this okay?

    bibiancheng wrote:
    would you please explain to me what
    String[] tokens = line.trim().split("\\s*,\\s*")"\\s*,\\s*" is a regex where \\s means whitespace and the * means "any number of".
    so \\s* means that it will grab all the whitespace if there is any.
    trim() removes white space from the beginning and end of the string.
    dont put a comma in the name.
    spaces allowed: "jane doe, 12-14-09, 428438, 6, 388473, 7, 187374, 3"
    it was just a recommendation. breaking it into separate lines would be fine.

  • How to read some lines from a text file using java.

    hi,
    i m new to java and i want to read some lines from a text file based on some string occurrence in the file. This file to be read in steps.
    we only want to read the file upto the first Occurrence of "TEXT" string.
    How to do it ,,,
    Kinldy give the code
    Regards,
    Sagar
    this is the text file
    dfgjdjj
    sfjhjkd
    ghjkdg
    hjkdgh TEXT
    ikeyt
    ujt
    jk
    tyk TEXT
    rukl
    r

    Hendawy wrote:
    Since the word "TEXT" is formed of 4 letters, you would read the text file 4 bytes by four bytes. Wrong on two counts. First, the file may not be encoded 1 byte per character. It could be utf-16 in which case it would be two byte per character. Second, even if it were 1 byte per character, the string "Text" may not start on a 4 byte boundary.
    Consider a FileInputStream object "fis" that points to your text file. use fis.read(byte[] array, int offset, int len) to read every four bytes. Convert the "TEXT" String into a byte array "TEXT".getBytes(), and yous the Arrays class to compare the equality of the read bytes with your "TEXT".getBytes()Wrong since it relies on my second point and will fail when fis.read(byte[] array, int offset, int len) does not read 4 bytes (as is no guaranteed to). Check the Javadoc. Also, the file may not be encoded with the default character encoding.
    The problem is easily solved by reading a line at a time using a BufferedReader wrapping an InputStreamReader wrapping a FileInputStream and specifying the correct character encoding.
    Edited by: sabre150 on Apr 29, 2009 2:13 PM

  • Help me...How to read the content if "Transfer-Encoding:chunked" is used?

    I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.If the HTTP header contains Content-Length,am getting the content length as below:
    public class HTTPResponseReader extends HTTPMessageReader
        String statusCode;
        public HTTPResponseReader(InputStream istream) throws IOException,                     NoSuchElementException
      BufferedInputStream distream = new BufferedInputStream(istream);
      retrieveHeader(distream);
      StringTokenizer st =  new StringTokenizer(new String(HTTPMessageReader.toArray(header)));
      versionProtocol = st.nextToken();
      statusCode = st.nextToken();
      String s;
      while (st.hasMoreTokens())
            s = st.nextToken();
            if (s.equals("Transfer-Encoding:"))
           transferEncoding = new String(st.nextToken());
         if (s.equals("Content-Length:"))
           contentLength = Integer.parseInt(st.nextToken());
         if (s.equals("Connection:"))
          connection = new String(st.nextToken());
          if (connection.equals("keep-alive")) mustCloseConnection = false;
       retrieveBody(distream);     
    }After getting the Content-Length,i used read method to read the content upto that content length.Then i concatenated the HTTP header and body and the requested site was opened.But some sites dont have Content-Length.Instead of that,Transfer-Encoding is used.I got the HTTP Response header as "Transfer-Encoding:chunked" for some sites.If this encoding is used how to get the length of the message body and how to read the content.
    Can anybody help me.
    Thanks in advance...
    Message was edited by:
    VeeraLakshmi

    Why don't you use HttpUrlConnection class to retrieve data from HTTP server? This class already supports chunked encoding...
    If you want to do anything by yourself then you need to read HTTP RFC and find all required information. Well in two words you may reject advanced encoding by specifying HTTP 1.0 in your request or download chunked answer manually. Read RFC anyway :)

Maybe you are looking for

  • Can't close docs in preview; command + W not working

    I created two "New from clipboard" images in Preview. I have no red button in the window to close them, but that might be my theme - I do have a gray button with an X. However, it doesn't work. Command + W also does not close them. I have cleared out

  • PL/PDF and object permissions

    Hi, We are currently examining PL/PDF to generate PDF reports from ApEx. The PL/PDF objects are installed in a separate schema (plpdf), including the "query_printing" procedure. Now we want to use the plpdf functionality from multiple other schema's

  • Working with Brushes in Photoshop 7

    b Q. Where has the Brushes Palette Gone? b A. The Brushes Palette can be found in the "Palette Well" section of the Options bar (right hand side). It can also be accessed from the "Window" menu. b Q. How do I customise my Brush settings? b A. Details

  • Backup physical standby database

    Hi, as for a backup & restore concept we are planning to implement a physical standby database using Oracle 10g on Sun Solaris. The idea is to use the standby database as backup source. What are the required steps and constraints, do i have to stop l

  • Error 39- core audio?

    i use garageband, cubase and protools, for my music.. i usually go thru garageband first to mix sounds and then the other programs until i end in pro tool.. all cool!! im getting this message of error 39 returned by core audio.. when this happen.. i