How do I create and display a text file?

Hello friends,
I am trying to create a simple unix like operating system with very basic functionality. I have a hard time trying to create a "mktext" file and actually display the contents of the text file with the "cat" command. For example:
// If I type
$$ mktext test.txt "We are one"
$$ Text file is created
// And if I type
$$ cat test.txt
// This line will appear
$$ "We are one" // Only the contents of the test.txt will display.
That is what I want to do, but currently stuck. I would appreciate any help and suggestions. Thanks...

This will do it:
import java.io.*;
import java.util.*;
public class Osys
     BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
public Osys()
     try
          while(true)
               System.out.print("$$ ");
               String s = keyboard.readLine();
               analize(s);
     catch(Exception e){}
private void analize(String s)
     if (s.trim().equals("")) return;
     StringTokenizer st = new StringTokenizer(s," ");
     if (!st.hasMoreTokens()) return;
     String s1 = st.nextToken();
     if (s1.equals("cat"))
          if (st.hasMoreTokens()) readIt(st.nextToken().trim());
          System.out.println("");  
          return;
     if (s1.equals("mktext"))
          if (st.hasMoreTokens()) writeIt(st.nextToken().trim(),s);
          System.out.println("");
          return;
// write
private void writeIt(String file, String line)
     BufferedWriter writer;
     StringTokenizer st = new StringTokenizer(line,"\"");
     if (st.countTokens() != 2) return;
     st.nextToken();
     try
          writer  = new BufferedWriter(new FileWriter(file));
             writer.write(st.nextToken()); 
          writer.close();
          System.out.println("$$ Text file is created");  
     catch (IOException e)
           System.out.println(""+e);  
// read
private void readIt(String file)
     BufferedReader reader = null;
     String         read   = null;
     try
         reader = new BufferedReader(new FileReader(file));
          while( (read = reader.readLine()) != null)
              System.out.println("$$ "+read);  
          reader.close();
     catch (IOException e)
           System.out.println(""+e);  
public static void main(String[] args)
     new Osys();
}Noah

Similar Messages

  • How to add header and fooder in text file

    Hi,
    i have created simple application for generate report from database into text file.
    But i need to add header and fooder in text file. I dont know is there any API for adding these.
    Can anyone help me to create header and fooder in text file.
    the below text are needs to be print in the header
    name of the table :
    Recorder type :
    file creation time:
    the below text are needs to be print in the footer
    Recorder Number:
    Record Type;
    the actual code is
                           pst = con.prepareStatement("select REQUEST, DOMAIN_NAME, TRUNC(DATE_OF_CONFIGURATION) AS dateofConfig  FROM employee where id=300");
                               rs = pst.executeQuery();
                            while (rs.next()) {
                                 request = rs.getString("REQUEST");
                                    domain_name = rs.getString("DOMAIN_NAME");
                                    dateofconfig = rs.getString("dateofConfig");
                                    System.out.println(request + " " + domain_name + " " + dateofconfig);
                                   data.add(request + " " + domain_name + " " + dateofconfig);
                            System.out.println("before calling method");
                            writeToFile(data, "c:/Employee.txt");
                            System.out.println("file created successfull");
                            rs.close();
                            pst.close();
           private static void writeToFile(List list, String path) {
                    BufferedWriter out = null;
                    try {
                            File file = new File(path);
                            out = new BufferedWriter(new FileWriter(file, true));
                            for (Object obj : list) {
                                String s=  obj.toString(); 
                                 out.write(s);
                                    out.newLine();
                            out.close();
                    } catch (IOException e) {
    }Thanks
    Jasmin
    Edited by: user13836688 on Mar 21, 2011 4:06 AM
    Edited by: user13836688 on Mar 21, 2011 4:07 AM
    Edited by: user13836688 on Mar 21, 2011 4:08 AM

    user13836688 wrote:
    i have created simple application for generate report from database into text file.First off, when posting code, use &#91;code]...&#91;/code]. or '' tags, not '<code>'.
    But i need to add header and fooder in text file. I dont know is there any API for adding these.
    Can anyone help me to create header and fooder in text file.Well you plainly have the code to write the file contents; and furthermore your report seems to be contained in a List called 'data'. Why not just add the header and footer lines to it? I'd also suggest making 'data' a LinkedList. That way you can add the header afterwards with no performance hit, just in case the information it contains isn't available at the start of your report loop.
    Winston                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to load date and time from text file to oracle table through sqlloader

    hi friends
    i need you to show me what i miss to load date and time from text file to oracle table through sqlloader
    this is my data in this path (c:\external\my_data.txt)
    7369,SMITH,17-NOV-81,09:14:04,CLERK,20
    7499,ALLEN,01-MAY-81,17:06:08,SALESMAN,30
    7521,WARD,09-JUN-81,17:06:30,SALESMAN,30
    7566,JONES,02-APR-81,09:24:10,MANAGER,20
    7654,MARTIN,28-SEP-81,17:24:10,SALESMAN,30my table in database emp2
    create table emp2 (empno number,
                      ename varchar2(20),
                      hiredate date,
                      etime date,
                      ejob varchar2(20),
                      deptno number);the control file code in this path (c:\external\ctrl.ctl)
    load data
    infile 'C:\external\my_data.txt'
    into table emp2
    fields terminated by ','
    (empno, ename, hiredate, etime, ejob, deptno)this is the error :
    C:\>sqlldr scott/tiger control=C:\external\ctrl.ctl
    SQL*Loader: Release 10.2.0.1.0 - Production on Mon May 31 09:45:10 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Commit point reached - logical record count 5
    C:\>any help i greatly appreciated
    thanks
    Edited by: user10947262 on May 31, 2010 9:47 AM

    load data
    infile 'C:\external\my_data.txt'
    into table emp2
    fields terminated by ','
    (empno, ename, hiredate, etime, ejob, deptno)Try
    load data
    infile 'C:\external\my_data.txt'
    into table emp2
    fields terminated by ','
    (empno, ename, hiredate, etime "to_date(:etime,'hh24:mi:ss')", ejob, deptno)
    this is the error :
    C:\>sqlldr scott/tiger control=C:\external\ctrl.ctl
    SQL*Loader: Release 10.2.0.1.0 - Production on Mon May 31 09:45:10 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Commit point reached - logical record count 5
    C:\>
    That's not an error, you can see errors within log and bad files.

  • How to create and handle a text file in CVI

    Is there any way to create and handle (like...open,write,read,truncate,close)  the .txt file in CVI?

    Sure. CVI is a regular C compiler and hence you can use all ANSI C functions. In addition you can use the File I/O functions from the utility library.

  • Include text file and display from text file

    Ok. I'm found the site with the monkey on the the flash thing and all it shows is a name, email and something else and I used it and it works by including a txt file and displaying text from that file as putting down this information
    name.text = this.name;
    and I can't find the site anymore to get help.
    I want to know how to include a PHP script that shows this information like this
    text=something I need&username=My Name&email=[email protected]
    I want to show this stuff on the flash but every time I execute by using it as localhost/test.php, it will show a sentax error.
    This is really stressing me out and I need a lot of help on this stuff.
    Can someone help me?

    ok. let me describe something else.
    there's 3 text boxes that is dynamic text.
    one of them is called name
    the other one is called email
    and last one is called location
    in the text file, it shows this for importing to the flash file
    name=My Name&email=EMAIL&location=My Location
    When viewing the flash file that you created, it shows the name, it shows the email, and it shows location.
    When I do it on my own even with a text file, it keeps on saying that there is an error on line 1.
    I found a site that shows how to do it and it shows what to put in a text file, and it shows the action script. On the FLA file that he shows me has a monkey on the flash file and it has 3 text boxes that I described above. As well as the text file, it is the same. I used the example and it worked but I can't find the example again. I don't know what happened to the website and I don't know what happened to the download I had but it is not downloaded any more. I have adanced systemcare pro so it clears out my recent web searches and my recent downloads so I can't find it. I did a google search on anything about action scripts. I even did a monkey action script search and I couldn't find it.
    It's making me mad and I don't know what to do. This is stressing me out way more than you think.
    UPDATE:
    I did a google search on a file I found in my www folder and I found it. finally.
    Here's the site.
    http://www.kirupa.com/developer/mx/externaldata.htm
    now, I need to figure out how to load it from a PHP file.

  • How do I read and write to text files on a remote computer's hard drive

    I would like to read and write data to a text file on a remote computer. This is easily accomplished using one of the file functions such as "write characters to file.vi". If I am already connected to the remote computer, all I need to do is specify the path to the particular file and it will work fine.
    My problem is that I want to connect to the remote computer programatically within LabVIEW (I do not want to have to use the computer's OS to establish the connection. Is there a function that I can use to do this?
    Thomas D. Schaefer
    Wells Manufacturing Corp

    Yariv,
    You should really start a new thread with a new question like this, so that more people see it. Some people look primarily at threads that have no responses yet. Also, don't post the exact same question in multiple places. Or, if you must cross-post to some other forum, make sure to mention it in your question text.
    I'm happy to be a brick in your Western Wall, but I'm not sure what the main objective is here. Is the main problem really getting access to the "X bytes received in Y seconds at Z bytes/sec" string? Or is it accomplishing the file transfer? And what OS and LabVIEW version are you running?
    I think your problem is that you the LabVIEW System Exec command does not allow for the degree of interactivity that you need if you want to issue a sequence of commands to a command-line executable. However, under Windows XP (and, presumably, other Windows versions, though I can't check), you can tell the FTP executable to use commands from a textfile script by using the -s switch, and you can override the prompts during multiple file transfers with the -i switch:
    ftp -i -s:FILEPATH SERVERNAME
    If you issue a command in this format to System Exec, and make sure to create a file at FILEPATH with your command sequence (one per line), then you should at least accomplish the FTP actions. This won't give you the transfer details in the standard output, unfortunately. However, if you just want a general sense of how much was transferred and how quickly it happened, you can code that in LabVIEW by getting the resulting file sizes and using Tick Count before and after the System Exec call to see how long the transfer took.
    Hope that helps,
    John

  • How do I create and send a zip file? I have Lion and I'm working in Word for mac

    To show you how little I know about any of this, I don't even know if this is the correct forum in which to ask this question. I'm a copywriter. I have a client in France. I have 15 word documents, 15 of the same documents in PDFs and a small Excel document to send him. Simple, mutlipage Word docs. Short two-page Excell sheet. I want to create a zip file for them to send to him. Can I do it? How? I have unzipped zip files other people have sent to me, but I've never created or sent one myself. I'm working in Word for Mac 2011. I have Lion. I'm using Mac's email. Please don't assume I know anything. I need very, very simple, play by play instructions. You are all very helpful, so I have high hopes.
    Nancy

    Visit:
    http://download.cnet.com/MacZip/3000-2250_4-10025248.html
    You will be able to both zip and unzip. If the recipient of your zipped file does not have zip, he/she will need to get it, or you could send him/her the above address so that he/she can unzip his/her file.
    (I wish the English language could settle on the use of something less clumsy that he/she him/her etc.)
    BTW, I think that you can zip only folders, not separate files, so put even one file into a folder before zipping).
    Message was edited by: SteveKir Added BTW

  • Store and Display doc/pdf files in the database using Forms

    Hi all,
    How can i store and display doc/pdf files in the database using Forms 10g?.
    Arif

    How to get up and running with WebUtil 1.06 included with Oracle Developer Suite 10.1.2.0.2 on a win32 platform
    Solution
    Assuming a fresh "Complete" install of Oracle Developer Suite 10.1.2.0.2,
    here are steps to get a small test form running, using WebUtil 1.06.
    Note: [OraHome] is used as an alias for your real oDS ORACLE_HOME.
    Feel free to copy this note to a text editor, and do a global find/replace on
    [OraHome] with your actual value (no trailing slash). Then it is easy to
    copy/paste actual commands to be executed from the note copy.
    1) Download http://prdownloads.sourceforge.net/jacob-project/jacob_18.zip
      and extract to a temporary staging area. Do not attempt to use 1.7 or 1.9.
    2) Copy or move jacob.jar and jacob.dll
      [JacobStage] is the folder where you extracted Jacob, and will end in ...\jacob_18
         cd [JacobStage]
         copy jacob.jar [OraHome]\forms\java\.
         copy jacob.dll [OraHome]\forms\webutil\.
      The Jacob staging area is no longer needed, and may be deleted.
    3) Sign frmwebutil.jar and jacob.jar
      Open a DOS command prompt.
      Add [OraHome]\jdk\bin to the PATH:
         set PATH=[OraHome]\jdk\bin;%PATH%
      Sign the files, and check the output for success:
         [OraHome]\forms\webutil\sign_webutil [OraHome]\forms\java\frmwebutil.jar
         [OraHome]\forms\webutil\sign_webutil [OraHome]\forms\java\jacob.jar
    4) If you already have a schema in your RDBMS which contains the WebUtil stored code,
      you may skip this step. Otherwise,
      Create a schema to hold the WebUtil stored code, and privileges needed to
      connect and create a stored package. Schema name "WEBUTIL" is recommended
      for no reason other than consistency over the user base.
      Open [OraHome]\forms\create_webutil_db.sql in a text editor, and delete or comment
      out the EXIT statement, to be able to see whether the objects were created witout
      errors.
      Start SQL*Plus as SYSTEM, and issue:
         CREATE USER webutil IDENTIFIED BY [password]
         DEFAULT TABLESPACE users
         TEMPORARY TABLESPACE temp;
         GRANT CONNECT, CREATE PROCEDURE, CREATE PUBLIC SYNONYM TO webutil;
         CONNECT webutil/[password]@[connectstring]
         @[OraHome]\forms\create_webutil_db.sql
         -- Inspect SQL*Plus output for errors, and then
         CREATE PUBLIC SYNONYM webutil_db FOR webutil.webutil_db;
      Reconnect as SYSTEM, and issue:
         grant execute on webutil_db to public;
    5) Modify [OraHome]\forms\server\default.env, and append [OraHome]\jdk\jre\lib\rt.jar
      to the CLASSPATH entry.
    6) Start the OC4J instance
    7) Start Forms Builder and connect to a schema in the RDBMS used in step (4).
      Open webutil.pll, do a "Compile ALL" (shift-Control-K), and generate to PLX (Control-T).
      It is important to generate the PLX, to avoid the FRM-40039 discussed in
      Note 303682.1
      If the PLX is not generated, the Webutil.pll library would have to be attached with
      full path information to all forms wishing to use WebUtil. This is NOT recommended.
    8) Create a new FMB.
      Open webutil.olb, and Subclass (not Copy) the Webutil object to the form.
      There is no need to Subclass the WebutilConfig object.
      Attach the Webutil.pll Library, and remove the path.
      Add an ON-LOGON trigger with the code
             NULL;
      to avoid having to connect to an RDBMS (optional).
      Create a new button on a new canvas, with the code
             show_webutil_information (TRUE);
      in a WHEN-BUTTON-PRESSED trigger.
      Compile the FMB to FMX, after doing a Compile-All (Shift-Control-K).
    9) Under Edit->Preferences->Runtime in Forms Builder, click on "Reset to Default" if
      the "Application Server URL" is empty.
      Then append "?config=webutil" at the end, so you end up with a URL of the form
          http://server:port/forms/frmservlet?config=webutil
    10) Run your form.sarah

  • Create and edit a PDF file

    Hi,
    Still very new on the Mac - how do I create and edit a pdf file on my iMac?
    Thanks for any info.

    Creating a PDF is really simple. From any application choose the print command (Command P) and in the lower left of the box you will see PDF, click PDF and then choose what you want to do. It will look similar to:
    For editing PDF files you can do some basic annotation editing using the Preview app which you will find in your Applications folder. However if you want to do more sophisticated editing then you will need to purchase an editor from the Mac App Store. Open the store type PDF Editor in the search field and you will find quite a few to choose from ranging from $2.99 to $99.99 depending on your needs.

  • How do i split content from the text file using tab and spaces...?

    Hi.. Just want to ask help to all the experts. Im new in java and i have this problem on how to split the contents of the text file. ill show you the contents in order to let you see what i mean.
    FileName: COL.txt
    AcctNo AcctName Primary Secondary Status Opendate
    121244 IPI Company Noel Jose Active 12/05/2007
    As you can see the content i want to split it per column.. Please help me

    Jose_Noel wrote:
    Hi prometheuzz,
    What do you mean by one thread...?You created two threads* with the same question in it. That way, people might end up giving you an answer that has already been posted in your other thread: thus wasting that person's time.
    Just don't create multiple threads with the same question please.
    * a thread is a post here at the forum

  • Custom themes: How do I create & edit an auto-text box?

    Hello
    Continuing my exploration of custom themes
    I have now found out how to make text boxes editable (control-command-option-T, that was carefully hidden!) and am now struggling with creating and editing 'auto text' boxes (not sure what their real name is in Keynote-speak)
    1) Creating new text boxes:
    Let's take a simple theme like White. One of the Masters is Title + Bullets Left. Now let's assume I want to create two text boxes with bulllets - the existing on the left and another on the right. In PowerPoint it's pretty simple: highly text box; copy; paste; move & resize as needed. Well Keynote won't let me Copy so that's out. If I create a fresh Text box, I can mimick the indent levels, bullets, font attributes, etc. (long and painful) but it still won't work because it is not a placeholder text box (fixed size) but a regular text box (size depends on content).
    I'm sure I'm missing a trick!
    2) Edit auto-text boxes
    Again, take any theme, say White again; If I choose a Master with a set text placement, say Photo Vertical, there is very little I can do with it: I can change text attributes and box size, but I can't touch the number of indentation levels for example. Then again what defines a text box as been 'double click here to edit' from a regular placeholder?
    Overall I think I'm missing a whole editing 'avenue' regarding masters - Anyone care to guide me?
    Thanks!
    Message was edited by: Moscool - typos!

    You can set a text field to be multi-line and tick off the option to scroll
    long text to have it automatically wrap, but you'll have a problem with the
    first partial line, since form fields can only be rectangular. Another
    problem might be the lines themselves, since you'll have to use a font size
    that will fit them exactly, or it will look odd. I would suggest getting
    rid of those lines altogether. They are not needed when filling in the form
    electronically. It's a relic from printed out forms where people had to
    hand-write their answers.

  • How do I create an outline around text please

    hi all, How do I create an outline around text please
    thanks,

    You can see here that you can simply apply a stroke to live text by double clicking the stroke icon in the bottom left of the toolbar and selecting a color. I chose red.
    If you select the text, then go to Type > Create Outlines, you get more options in the stroke palette, like whether the stroke is aligned to the outside or inside of the text object's boundary. The text below is outlined with the stroke aligned to the outside.

  • How can i create n display label dynamically

    Hai, I want to create a label dynamically, meant when i pressed a button once one label generated for the next click of button another label. like this,
    so i need to know how to create and display a label.
    regards

    Hi,
    Armin's solution already answers your question.
    Create a value attributre CreatLabel..of type boolean and set it to false in init.
    Then in the button's action handler ,set it to true.
    And write this code in wdDoModifyView.
    In wdDoModifyView():
    if ( wdContext.currentContextElement().getCreateLabel() ){  /* create new label with automatic ID */  IWDLabel label = (IWDLabel) view.createElement(IWDLabel.class, null);  /* add label to some container */  someContainer.addChild(label);  /* reset creation flag */  wdContext.currentContextElement().setCreateLabel(false);}
    You should not create view element outside wdDoModifyView. So we write this in the wdDoModify view..a nd control when it is executed.. by means of setting CreateLabel value attribute..
    Regards
    Bharathwaj
    Message was edited by: Bharathwaj R

  • How to create a tab-delimited text file?

    Hi,
    I need to create a tab-delimited text file at presentation server getting content from an internal table. My file should also have a header - also tab-delimited. Data for a header is stored in some work area.
    Any ideas how to add tab-delimiter into a text file? Or should I go for a HEX file and use
    CONSTANTS: c_tab TYPE x VALUE '09'.
    and separate my data with this constant instead?
    Any thoughts whould be appreciated.
    TIA
    Ivaylo Mutafchiev

    Hi Ivaylo,
    Refer sample code:
        IF i_final_head[] IS NOT INITIAL.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
              filename                = lcl_filename
              filetype                = 'ASC'
              write_field_separator   = 'X'
            TABLES
              data_tab                = i_final_head
            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 s000 WITH text-031.
            EXIT.
          ENDIF.
        ENDIF.
    Reward points if this helps.
    Manish
    Message was edited by: Manish Kumar

  • 2 Custom Fields-create and display

    In addition to the standard fields available within the Whou2019s Who service, we need to create and display 2 custom fields within the employee search functionality in ESS. 
    Can someone walk me through the steps please?

    Hello,
    There are 2 sections of search available.
    1 is normal search and 1 is advances search.
    Well for advanced search you can very much follow my earlier reply.
    And you can also have a look at below thread...
    ESS Who is Who - Add search criteria
    I guess you want to add extra field in normal search.
    I am not sure how to do it....as Siddharth (In link I pasted above) says that he himself have never seen any changes in normal search.......
    But still you can give below method a try.....
    http://wiki.sdn.sap.com/wiki/display/profile/ESS%2bPersonal%2bInformation%2bUI%2benhancement%2bwithout%2bmodification?bc=true

Maybe you are looking for

  • Multiple devices no longer work with Airport Extreme

    I can't get multiple devices to work with my Airport Extreme any longer. Normally, I have 4 wireless devices with my Airport Extreme: MacBook Pro, iPhone 5, Sony Wireless Blu-Ray Player, and Windows Laptop. On a daily basis, I use the MacBook Pro and

  • HP LaserJet 3030 not detected

    I have connected my HP LaserJet 3030 to my new Airport Extreme yet it is not being detected by the Airport Extreme. I have updated my drives to Gutenprint 5.2.5 to no avail. Please help.

  • Can't forward texts as dialogue box pre-populated with old text

    Hi - I've seen a few old posts about this but no one has had an answer. When I either try to forward a message on my iPhone (iOS 6.1.2), instead of the message I have selected to forward appearing in the window, an old message appears. This also happ

  • N8 - Service is unavailable

    Hello, I'm using N8. I'm trying to update my Nokia Belle using my computer but still cannot. I'm using Nokia Suite 3.3.89. When I try to update, the message is 'Service is unavailable'. May I know why this happen...?

  • Weblogic 11g reports url

    I have just setup a new dev environment for a development team on Weblogic 11g (10.3.2.0) with forms and reports. In iAS, I could run a report with the url: http://myserver/reports/rwservlet?server=rep_server&report=myreport.RDF&userid=user1/password