Saving a LinkedList into a text doc using bufferwriter

hi
I'm having some problem attempting to save my linked into a text doc(.txt). By using the scanner class i to read another text doc and have it put each work in that document as an single element in the linkedlist. But when i try to write the linked list into a text doc it only writes the last word / element that is in the linkedlist into a text document. How do i get my bufferwriter or filewrite to same all the words and prehaps in a format that i want?
import java.util.*;
import java.io.*;
public class LibraryLinkedList {
    public static void main(String[] args) throws FileNotFoundException,
   IOException{
      File file1 = new File(args[0]);
        Scanner in = new Scanner(file1);
        LinkedList<String> lst = new LinkedList<String>();
        //... Read and build list of words.
        while (in.hasNext()) {
            String word = in.next();
            lst.add(word);
       ///  loop to print list forward.
        //    Could also use an Iterator (forward only) or
        System.out.println(" Print words in order of entry");
        for (String s : lst) {
            System.out.println(s);
        /// this print statement is for testing
         BufferedWriter out = new BufferedWriter(new FileWriter(
        "s.txt"));
      PrintWriter output = new PrintWriter(out);
      output.print(s);
      output.close();
}eg.
1. i have a doc with words("apple chair book house")
2. i have a testing print statement which prints the words that have been scanned and placed into linked list and it prints it like this
apple
chair
book
house
3. then when i attempt to write into a txt doc it only has ("house") in the doc

hey
say i wanted to add a numbering system for each linkedlist item, i've used another for loop to try and attempt this but what happens is that it loops too much.
eg what i wanted was something like
1. apple 2.house 3. somthing ect
but what happens is
1.apple 2.apple 3.apple ... 15.apple 1.house 2.house 3 house..... 15.house
my code is as follows
for(String g :lst) {
            for(int i = 1; i < lst.size(); i++){
            //out.write("#" + i); for loop placing numbers and increasing
            out.write(" #"+ i + g);}
  out.write(" "); // add a new line
out.close();
    }

Similar Messages

  • How to convert a HTML files into a text file using Java

    Hi guys...!
    I was wondering if there is a way to convert a HTML file into a text file using java programing language. Likewise I would also like to know if there is a way to convert any type of file (excel, power point, and word) into text using java.
    By the way, I really appreciated the help that you guys gave me on my previous topic on how to extract tests from a pdf file.
    Thank you....

    HTML files are already text files. What do you mean you want to convert them?
    I think if you search the web, you can find things for converting those MS Office files to text (or extracting text from them, as I assume you mean).

  • Saving results displayed on jsp into a text file using struts actions

    Hi,
    i am developing a web application using struts...the basic functionality of the system is to retrieve data from the database based on the search conditions given by the user. Hence for different search criteria there are different JSP result screens. Struts and persistence are being used. The user should be able to save/view the data loaded on the screen in a text file when he clicks on the save button.
    I am supposed to write an action for fileoutput which can be used by all the result screens...instead of writing the same code in all the jsp pages...how do i go about it? I have already written an action class for the same but when i click on the save button a blank IE screen opens up instead of the open /save dialog box...i have also added mappings for the same in struts config xml file....any suggestions?

    Again, you have posted to the wrong board. SignalExpress is an application written in LabVIEW.

  • How to store data into log file(.doc) using CVI

    The purpose is to store the capture data(from my cvi program) and store into the log file (.doc). so at the end of the program run I can retrieve the doc file where the data  store to do my analysing .
    Why do this: I wanted to create my program into .exe file that why I need this method or do u have other method to intro?
    Any ideal or note or example to share? Pls help

    If you are explicitly trying to create a Microsoft Word document, then CVI comes with Word Report instrument that can be used to generate such files. The instrument is located in toolslib\activex\word\wordreport.fp, while a sample program can be found in samples\activex\word\wordrpt.cws.
    I suggest you take a look at the example program that illustrates the fundamentals of this instrument, next you can start designing your own application using that instrument.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Changing HTML to text file using java

    Hi,
    I am doing a project in which i have to read news articles from websites. I have tried XML but for that i need to know which tag has the article in it. Since i have to read from various websites so each site used different tags for different informations.
    Is there anyway that i can change an HTML file into a text file using java. Maybe some command that removes all the HTML tags and gives just the information. Is there anything else that anyone would like to recommend?
    Thanx
    yafis

    Maybe something like this:
    import java.io.*;
    import java.net.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    class GetHTMLText
         public static void main(String[] args)
              throws Exception
              EditorKit kit = new HTMLEditorKit();
              Document doc = kit.createDefaultDocument();
              // The Document class does not yet handle charset's properly.
              doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
              // Create a reader on the HTML content.
              Reader rd = getReader(args[0]);
              // Parse the HTML.
              kit.read(rd, doc, 0);
              //  The HTML text is now stored in the document
              System.out.println( doc.getText(0, doc.getLength()) );
         // Returns a reader on the HTML data. If 'uri' begins
         // with "http:", it's treated as a URL; otherwise,
         // it's assumed to be a local filename.
         static Reader getReader(String uri)
              throws IOException
              // Retrieve from Internet.
              if (uri.startsWith("http:"))
                   URLConnection conn = new URL(uri).openConnection();
                   return new InputStreamReader(conn.getInputStream());
              // Retrieve from file.
              else
                   return new FileReader(uri);
    }

  • I am looking for an application that would allow me to open a word doc, and take notes in the .doc using a stylus pen.  I'd then like to convert those notes to text, and then be able to copy / paste those notes into an email.  Does this app exist?

    I am looking for an application that would allow me to open a word doc, and take notes in the .doc using a stylus pen.  I'd then like to convert those notes to text, and then be able to copy / paste those notes into an email.  Does this app exist?  It seems like we were doing these same types of things with Palm Pilots years ago, one would think this would work with iPads?

    I don't believe it will open a Word document, but Writepad allows for handwritten conversion of notes to text and then to email. Might help you some of the way...

  • Saving the data into the tab limited text file

    Dear Friends ,
    please help me at the earliest possible , i want to store the data into an text file which is tab limited ,previously i was able to the same into the excel sheet using the jakarta HSSF POI , an open source library to store the data into the EXCEL sheet , now friends please tell me whether is there any other open source to store the data into the tab limited text file what i mean by tablimited is the data is to be saved as
    Name        Email-id        phone          streeet          city
    sri            @some.com     9434           jahdui          hye
    asdf         @.com           3455           sdgsdf         retlike this so please suggest me
    thank you in advance,
    bye
    sriharsha

    Consult the docs for BufferedWriter and from there.
    regards
    Christian
    import java.io.*;
    public class Test
         public static void main(String[] args)
              BufferedWriter writer;
              String[][] s = { {"Name","Email-id","phone","streeet","city"},
                        {"sri","@some.com","9434","jahdui","hye"},
                        {"asdf","@.com","3455","sdgsdf","ret"}};
              try {
                   writer = new BufferedWriter(new FileWriter("out.txt"));
                   for (int j=0; j< s.length; j++) {
                        for (int i = 0; i < s[j].length; ++i) {
                             writer.write(s[j]+"\t");
                        writer.newLine();
                   writer.close();
              } catch (IOException e) {
                   e.printStackTrace();

  • I have two pdf docs that I used Acrobat to convert to word docs.  How do I extract one page from one doc to insert into the other doc?

    I have two pdf docs that I converted to Word Docs using Acrobat Pro.  How do I extract one page from the first doc and insert it into the second doc?  When I "select all" it grabs the entire document.  I need to take pages out, put other pages in, and edit some of the text.

    HI djlarp,
    Try triple-clicking in the text that you want to select--it can sometimes be tricky to select text in a converted document. If that doesn't work, it could be that the PDF document was created from a scanned document, and OCR wasn't enabled when you converted the document. (However, OCR is enabled by default when you convert via the ExportPDF website.)
    If you're unable to select text by triple-clicking, let us know. I would be happy to take a closer look at your files.
    Best,
    Sara

  • When trying to convert a pdf file into a word doc, i only get the graphics but not the text. How do i remedy this?

    When trying to convert a pdf file into a word doc I only get graphics but no text. What to do?

    Hey hamsa142,
    I think you are converting a scanned PDF to word.
    You might need to run OCR first to make the text recognizable and then convert it to word.
    Regards,
    Anubha

  • Importing and flowing multiple text docs into InDesign CS3

    I have multiple plain text files where each runs several pages long that I want to import into one document in ID CS3. I want to import them and have them flow in a single threaded text frame one after another over multiple pages. With a single multi-page text doc all I have to do is select Place and hold down the shift key and InDesign will add the necessary pages and flow the copy until the end of the doc. However, if I shift select the docs and try import them into a text frame by holding down the shift key, it will just flow the first doc in the group with no indication of overset text. I have tried placing multiple text docs holding down the shift and command key and that brings in all my docs on the first page but in separate text boxes with overset text for each doc. Is there a way to do this in InDesign or perhaps a plugin that can do this?
    Thanks
    Randy

    I tried to find this. It was posted 4/21/08 by Peter Kahrel (I can tell, because I can see my side of the discussion in my Sent folder) in response to a post I made entitled "Multiple Files". Maybe I'm not searching the forum archives properly, or maybe this was during the time last year when Adobe was trying (and failing) to update the forums. In any case, I'm sure at this point that Peter posted this for public consumption, so I don't think he's going to mind if I post it again:
    // Description: Place multiple textfiles as one story
    #target indesign
    preset = "/d/books/test/*.doc";
    app.wordRTFImportPreferences.useTypographersQuotes = false;
    app.wordRTFImportPreferences.convertPageBreaks = ConvertPageBreaks.none;
    app.wordRTFImportPreferences.importEndnotes = true;
    app.wordRTFImportPreferences.importFootnotes = true;
    app.wordRTFImportPreferences.importIndex = true;
    app.wordRTFImportPreferences.importTOC = false;
    app.wordRTFImportPreferences.importUnusedStyles = false;
    mask = prompt( 'Enter a file path/mask.\r\r' +
       'Examples:\r' +
       'd:\\books\\test\\*.rtf   /d/books/test/*.rtf', preset );
    if( mask == null ) exit();  // Cancel pressed
    ff = Folder( File(mask).path ).getFiles( File(mask).name );
    if( ff.length > 0 )
       placed = [];
       missed = [];
       tframe = app.documents.add().textFrames.add(
          { geometricBounds : [36, 36, 400, 400] } );
       placedstory = tframe.parentStory;
       app.scriptPreferences.userInteractionLevel = 
          UserInteractionLevels.neverInteract;
       pb = initprogressbar( ff.length, 'Loading');
       for( i = 0; i < ff.length; i++ )
          pb.value = i;
          try
             placedstory.insertionPoints[-1].contents = '£0';
             placedstory.insertionPoints[-1].place( ff[i] );
             placedstory.insertionPoints[-1].contents = '\r\r';
             placed.push( ff[i].name );
          catch(_)
             missed.push( ff[i].name );
       app.scriptPreferences.userInteractionLevel = 
          UserInteractionLevels.interactWithAll;
       inform = '';
       if( placed.length > 0 )
          inform = 'Placed ' + ff.length + ' files (in this order):\r\r' + placed.join('\r');
       if( missed.length > 0 )
          inform += '\r\rCould not place:\r\r' + missed.join('\r');
       delete_empty_frames ();
       alert( inform );
    else
       alert( mask + ' not found.' );
    // End
    function delete_empty_frames ()
       app.findGrepPreferences = app.changeGrepPreferences = null;
       app.findGrepPreferences.findWhat = '\\A\\Z';
       var empties = app.activeDocument.findGrep (true);
       for (var i = 0; i < empties.length; i++)
          empties[i].parentTextFrames[0].remove()
    function initprogressbar( stop, title)
       var progresswindow = new Window('palette', title);
       var progressbar = progresswindow.add( 'progressbar', undefined, 1, stop );
       progressbar.preferredSize = [200,20];
       progresswindow.show()
       return progressbar;
    Copy and paste everything between the hyphen lines (not including the hyphen lines) into a text editor and save with a .js extension and put it in your scripts folder. Should be something like:
    D:\Program Files\Adobe\InDesign CS3\Adobe InDesign CS3\Scripts\Scripts Panel
    After alphabetizing your files and putting them in their own folder, copy the path and run the script. It will make a new folder and place all your files in one continuous story. I don't know how it will work with .txt files.
    Ken Benson

  • Spool SQl data into text file using dynamic sql

    Hi,
    I am spooling output data into text file using command
    select 'select t.mxname,bo.lxtype,t.mxrev'||chr(10)||'from mx_1234567'||chr(10)||
    'where <condition>';
    here mxname varchar(128),lxtype(128),mxrev(128) all are of varchar type.I want the output in format
    e.g Part|1211121313|A
    but due to column width the output,I am getting is with spaces.
    "Part then blank spaces |1211121313 then blank spaces |A"
    how can I remove these spaces between columns.I used set space 0 but not working.
    Thanks in advance.
    Your help will be appreciated.

    Hi Frank,
    I have seen your reply for SET LINE SIZE function. But, I could not be able to understand it.
    I am facing similar kind of issue in my present project.
    I am trying spool more than 50 columns from a table into flat file. Because of more column lengths in few columns, i am getting space. There are so many columns with the same issue. I want to remove that space.so that, data can fit perfectly in one line in .txt file without any wrap text.
    Below is my sample query.sql. Please let me know the syntax. My mail id : [email protected]
    --Created : Sep 22,2008, Created By : Srinivasa Bojja
    --Export all Fulfillments
    --Scheduled daily after 1:00am and should complete before 3:30am
    WHENEVER SQLERROR EXIT SQL.SQLCODE
    SET LINESIZE 800
    SET WRAP OFF
    SET PAGESIZE 800
    SET FEEDBACK OFF
    SET HEADING ON
    SET ECHO OFF
    SET CONCAT OFF
    SET COLSEP '|'
    SET UNDERLINE OFF
    SPOOL C:\Fulfillment.txt;
    SELECT SRV.COMM_METHOD_CD AS Method,
    SRV.SR_NUM AS "Fulfillment Row_Id",
    CON.LAST_NAME AS "Filled By"
    SRV.SR_TITLE AS Notes,
    SRVXM.ATTRIB_04 AS "Form Description"
    FROM SIEBEL.S_SRV_REQ SRV,
    SIEBEL.S_SRV_REQ_XM SRVXM,
    SIEBEL.S_USER USR,
    SIEBEL.S_CONTACT CON
    WHERE SRV.ROW_ID = SRVXM.PAR_ROW_ID AND
    SRV.OWNER_EMP_ID = USR.ROW_ID AND
    CON.ROW_ID= SRV.CST_CON_ID;
    SPOOL OFF;
    EXIT;

  • Uploading into database table from text file using tab (GUI_UPLOAD)

    i have small doubt
    i have 3 fiels in text file using tab as separator
    i need to update into database table 'ZABPSP_01'
    from 's.txt' located in local disk.
    My code is below.
    Please let me know the correction.
    Awaiting for ur response.
    Thanks in advance
    REPORT  ZABPSPPRG_02.
    TABLES: LFA1,MARA,KNA1,ZABPSP_01.
    DATA:  begin of itab occurs 0,
    IKUNNR type zabpsp_01-kunnr,
    IMATNR type zabpsp_01-matnr,
    IADRNR type zabpsp_01-adrnr.
    DATA:END OF ITAB.
    DATA: FILENAME1 TYPE STRING.
    FILENAME1 = 'C:/s.txt'.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = FILENAME1
      FILETYPE                      = 'ASC'
       HAS_FIELD_SEPARATOR           = 'X'
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
      NO_AUTH_CHECK                 = ' '
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      TABLES
        DATA_TAB                     = itab.
    EXCEPTIONS
      FILE_OPEN_ERROR               = 1
      FILE_READ_ERROR               = 2
      NO_BATCH                      = 3
      GUI_REFUSE_FILETRANSFER       = 4
      INVALID_TYPE                  = 5
      NO_AUTHORITY                  = 6
      UNKNOWN_ERROR                 = 7
      BAD_DATA_FORMAT               = 8
      HEADER_NOT_ALLOWED            = 9
      SEPARATOR_NOT_ALLOWED         = 10
      HEADER_TOO_LONG               = 11
      UNKNOWN_DP_ERROR              = 12
      ACCESS_DENIED                 = 13
      DP_OUT_OF_MEMORY              = 14
      DISK_FULL                     = 15
      DP_TIMEOUT                    = 16
      OTHERS                        = 17
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    IF sy-subrc EQ 0.
    zabpsp_01-kunnr = ITAB-IKUNNR.
    zabpsp_01-matnr = ITAB-IMATNR.
    zabpsp_01-adrnr = ITAB-IADRNR.
    WRITE : / ' UPLOAD SUCCESS ' .
    ENDIF.
    \[subject changed, don't write everything in upper case!\]
    Edited by: Jan Stallkamp on Aug 6, 2008 2:39 PM

    Hi,
    After upload modify the code like below. Also change the file name as some one suggested already. If u are still facing problems then check in debug mode what is happening after FM call.
    CALL GUI_UPLOAD FM.
    IF sy-subrc EQ 0
    IF NOT itab[] IS INITIAL.
    MODIFY ZABPSP_01 FROM TABLE itab.
    WRITE : / ' UPLOAD SUCCESS ' .
    ELSE.
    WRITE 'No data in file'.
    ENDIF.
    ELSE.
    WRITE 'Upload failure'.
    ENDIF.
    Thanks,
    Vinod.

  • G'day, i am trying to type into an adobe document using the typewriter function. However everytime after i type the text vanishes. It is almost as if the text is white and vanishes into the background. However this is not the case as the works are not vis

    G'day,
    I need some help, i am trying to type into an adobe document using the typewriter function.
    However every time after i type the text vanishes. It is almost as if the text is white and vanishes into the background.
    This is not the case as the works are not visible regardless of the background color.
    The text box remains available and can be edited if clicked on, also if i double click on it the typed words become visible and editable, however once i close the box i cannot see them on the screen.
    I would appreciate any help i can get, i cant seem to do anything using properties or view.
    Thanks 
    Tiernan

    Hi Sara,
    See response to your questions below:
    1.     Are you running into this issue in a specific PDF, or in all of them?
    A.     All of them
    2.     What version of Acrobat are you using (and, are you on Mac OS or Windows?).
    A.     Using Acrobat 10.0\Acrobat on Windows
    3.     If you look at the text properties on the Tools panel (under Format), what color is the text swatch?
    A.     Test swatch for the text is black
    4.     What happens if you change the text color?
    A.     Nothing.
    I look forward to hearing back from you.

  • Saving multiple records into text file

    Can I save multiple records into a text file at one go?
    My application has a list of data displayed there and when the user clicks on the save button it will save all the records on the screen.
    It works but it only saves the last record.
    Here are my codes
    // this is to display the list of data
    private JLabel[] subjects=new JLabel[20];
    private JLabel[] subTotal=new JLabel[20];
    private JLabel[] codes=new JLabel[20];
    private JLabel[] getTotal=new JLabel[20];
    String moduleCodes;
    String getPrice;
    double price;
    int noOfNotes;
    public testapp(Subjects[] subList)
    int j=0;
                double CalTotal=0;
              for (int i=0; i<subList.length; i++)
                   subjects[i] = new JLabel();
                   subTotal[i] = new JLabel();
                   codes=new JLabel();
                   getTotal[i]=new JLabel();
                   if (subList[i].isSelected)
                        System.out.println(i+"is selected");
                        subjects[i].setText(subList[i].title);
                        subjects[i].setBounds(30, 140 + (j*30), 400, 40);
                        subTotal[i].setText("$"+subList[i].price);
                        subTotal[i].setBounds(430,140+(j*30),100,40);
                        codes[i].setText(subList[i].code);
                        getTotal[i].setText(subList[i].price+"");
                        CalTotal+=subList[i].price;
                        contain.add(subjects[i]);
                        contain.add(subTotal[i]);
                        j++;
                        moduleCodes=codes[i].getText();                              
                        getPrice=getTotal[i].getText();
                        noOfNotes=1;
    // this is where the records are saved
         public void readRecords(String moduleCodes,String getPrice,int notes)throws IOException
              price=Double.parseDouble(getPrice);
              String outputFile = "testing.txt";
              FileOutputStream out = new FileOutputStream(outputFile, true);      
         PrintStream fileOutput = new PrintStream(out);
              SalesData[] sales=new SalesData[7];
              for(int i=0;i<sales.length ;i++)
                   sales[i]=new SalesData(moduleCodes,price,notes);
                   fileOutput.println(sales[i].getRecord());
              out.close();

    I suggest writing a method that takes a SalesData[]
    parameter and a filename. Example:
    public void writeRecords(SalesData[] data,
    String filename) throws IOException
    BufferedWriter out = new BufferedWriter(new
    FileWriter(filename, true));
    for (int i = 0; i < data.length; i++)
    out.write(data.getRecord());
    out.newLine();
    out.close();
    And it's good to get in the habit of doing things like closing resources in finally blocks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Issue while uploading .TIFF file into Standard text using RSTXLDMC

    Hi All,
    We are facing issues while uploading .TIFF file into standard text through program RSTXLDMC.
    Getting the following error.
    TIFF format error: No baseline TIFF 6.0 file.
    The image is a colored one.
    Please provide me solution if anyone has worked in this area.
    Thanks in Advance,
    Anand Raj Kuruba.

    Hi,
    Often this error occurs because the TIFF file you have has been saved with some form of compression.  You need to open in a picture edit program and save as TIFF making sure options are set so there is no compression.
    Andrew

Maybe you are looking for

  • CrystalReportViewer: "Missing parameter values with implemented error event

    I'm using the CrystalReportViewer in APS.net (C#), and try to display a report in it. I've implemented the error event of the viewer to show the user a different error message than the viewer itself does.          this.CrystalReportViewer.Error += ne

  • 10.6.4 problems

    Earlier today I installed the 10.6.4 update, and the Sarafi update. Upon restarting the machine I noticed that some settings had been erased/changed: 1. Date/Time: "Your computer's clock is set to a date before Ja 1, 2008..." My clock is set for 5:10

  • How can I disable phone number recognition in the built-in Notes app for iPhone 4S?

    I don't want 7-digit numbers to be automatically recognized as phone numbers. It's too easy to inadvertently tap a number and summon a dialog box asking if I want to place a call. I don't routinely keep phone numbers in Notes, so this feature isn't o

  • My suddenly stop working 4g

    my iphone suddenly stop working

  • HTTP code 500 trying to connect to VSO

    Hi; We've been using VSO for months with no problem. Now all of a sudden we're getting: How do we fix this? We're down with VSO not available!!! What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing