Reading file anf using input for main

Hello Amigos,
I have the following code but I have my doubts if it will work for what I want. I want to read in a file that will call a method with specific arguments.
Example:
Method:
addTwoNumbers(int oneNum, int twoNum);
File: sum.txt:
addTwoNumbers(1,5);
addTwoNumbers(8,2);
addTwoNumbers(3,10);
My confusion starts with the PrintWriter definition. I am not quite sure how to implement it and I don't find an example or online reference about this topic.
Thanks in advance...
try
            BufferedReader fileIn  = new BufferedReader( new FileReader("process.txt"));
            String oneLine;
            System.out.println("Reading File...");
          while( ( oneLine = fileIn.readLine( ) ) != null )
               PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(fileIn.readLine()));
                  printWriter.println(oneLine);
                  printWriter.close();
                  System.out.flush();
             System.out.println("Done Reading File.");
        }

It's hard to tell where to start. I'll post a brief example of how to read something in from a text file and use it. It's not robust, but it serves as a starting point, I suppose.
sum.txt
1,3
2,4
5,6
SumDemo.javaimport java.io.*;
public class SumDemo
    public static void main(String[] args)
        new SumDemo().go();
    public void go()
        String fileName = "sum.txt";
        try {
            BufferedReader in = new BufferedReader(new FileReader(fileName));
            String line;
            while ((line = in.readLine()) != null)
                String[] nums = line.split(",");
                int x = Integer.parseInt(nums[0]);
                int y = Integer.parseInt(nums[1]);
                System.out.println(addTwoInts(x, y));
        catch (IOException ioe) { ioe.printStackTrace(); }
    public int addTwoInts(int x, int y)
        return x + y;
}

Similar Messages

  • Happy Holidays.  I have Adobe Actobat 7.0 Standard for quite a while, and I'm happy with it. I use it for mainly filings at the federal court.  They require PDF.  I use two computers in two different states for work.  I realize my Adobe 7.1 is a few years

    .  I have Adobe Actobat 7.0 Standard for quite a while, and I'm happy with it. I use it for mainly filings at the federal court.  They require PDF.  I use two computers in two different states for work.  I realize my Adobe 7.1 is a few years old, but sometimes I have difficulty using it with the other days downloading a boarding pass, and e filing at the USDC. .  There's a problem with Adobe Flash, media, etc.  and other Adobe programs, (which I use for downloading boarding passes for airlines, etc.) so basically I have to delete these other Adobe programs, besides the Adobe Acrobat 7.0 Standard if I want to 7.0 Standard to work.  I periodically download the updates, but there's still a problem. My question is:  Can or should I purchase another program to update the present Adobe Acrobat 7.0 standard, or just buy a new program such as the Adobe 11?  Am I mistakenly doing something wrong, such as when I download?  I'm an old valued customer so I don't want to spend a lot of money since I am replacing my Dell XP for a new computer now, and my other computer is a Dell Vista.
    I'd appreciate your valued advice.

    If you are getting a new computer (for a PC it would have Win 7 or 8), then you will need to purchase XI if you wish to continue using Acrobat. Acrobat 7 is not compatible with these systems (and probably the same for MAC systems), though sometimes workarounds are possible, though not easy to use. I guess the answer is to buy the new version. Try http://www.adobe.com/products/catalog/software._sl_id-contentfilter_sl_catalog_sl_software _sl_mostpopular.html, click on the Buy for Acrobat, and then select the version you want.

  • What is a valid location for autorecovery files when using Word for MAC?

    What is a valid location for autorecovery files when using Word for MAC?

    Microsoft Word for Mac support forums is probably a better place to ask.

  • How to create sharepoint Group with read only permissions using powershell for entire site ?

    How to create sharepoint Group with read only permissions using powershell for entire site (including subsites and top level site)

    Hi
    using (SPSite site = new SPSite(url))
    using (SPWeb web = site.OpenWeb())
    SPUserCollection users = Web.AllUsers;
    SPUser owner = users[string.Format("{0}{1}", "Domain", "Owner Username")];
    SPMember member = users[string.Format("{0}{1}", "Domain", "Default Member Username")];
    SPGroupCollection groups = Web.SiteGroups;
    string GroupName = “Super Exclusive”;//your group name
    string GroupDescription = “Super exclusive group description.”;
    groups.Add(GroupName, owner, member, GroupDescription);
    SPGroup NewSPGroup = groups[GroupName];
    SPRoleDefinition role = Web.RoleDefinitions["Read"];
    SPRoleAssignment roleAssignment = new SPRoleAssignment(NewSPGroup);
    roleAssignment.RoleDefinitionBindings.Add(role);
    Web.RoleAssignments.Add(roleAssignment);
    Web.Update();
    Please 'propose
    as answer' if it helped you, also 'vote
    helpful' if you like this reply.

  • I downloaded Yosemite on new iMac and now can no longer open spreadsheet files created using Excel for the iMac.  I used to be able to do so on this new computer.  What can I do?

    I downloaded Yosemite on my new iMac and now can no longer open spread sheet files I created on my old iMac using Excel for the iMac.  I used to be able to open these files on my new computer before Yosemite.

    I downloaded Yosemite on my new iMac and now can no longer open spread sheet files I created on my old iMac using Excel for the iMac.  I used to be able to open these files on my new computer before Yosemite.

  • Unable to configure file adapter using FCC  for Multilevel hierarchy

    Hi Experts,
    Can anyone help me in configuring the Receiver file adapter with FCC for the structure given below
    <Root>
    <Level1>
         <Ele1>
         <Ele2>
         <Level2>
                <Ele2_1>
                <Ele2_2>
                <Level2a>
                        <Ele2a_1>
                        <Ele2a_2>
                </Level2a>
         </Level2>
    </Level1>

    Hi dineshmale,
    I have do this Multilevel hierarchy before. FCC can directly configure this scenario. But I don't know you output format. What my format shown below(here i use '#' instead of space):
    Level1_Field1##Level1_Field2##Level1_Field3##Level2_Field1##Level2_Field2##Level3_Field1##Level1_Field2
    #################################################################Level3_Field1##Level1_Field2
    #######################################Level2_Field1##Level2_Field2##Level3_Field1##Level1_Field2
    #################################################################Level3_Field1##Level1_Field2
    Level1_Field1##Level1_Field2##Level1_Field3##Level2_Field1##Level2_Field2##Level3_Field1##Level1_Field2
    #################################################################Level3_Field1##Level1_Field2
    #######################################Level2_Field1##Level2_Field2##Level3_Field1##Level1_Field2
    #################################################################Level3_Field1##Level1_Field2
    #################################################################Level3_Field1##Level1_Field2
    FCC Parameter:
    Recordset Structure: Level1,Level2,Level3
    Level1.fieldSeparator = (2 spaces)
    Level2.beginSeparator = (some spaces according to the length of the fields in Level1)
    Level2.fieldSeparator = (2 spaces)
    Level3.beginSeparator = (some spaces according to the length of the fields in Level1and Level2)
    Level3.fieldSeparator = (2 spaces)
    Level3.endSeparator = \n
    There are some points:
    1. the endSeparator for Level1 and Level2 doesn't work.
    2. the first begin separator in Level2 and Level3 doesn't work.
    3. The last field of super node and the first field of child node is separated by the (child).fieldSeparator.
    4. ....
    What's more, I have write a blog of FCC For Hierarchical Structure in Receiver Channel just now. So it need two days for Approval. Let me know for any issues.
    Edited by: guKidd on Dec 14, 2010 7:52 AM
    Edited by: guKidd on Dec 14, 2010 7:54 AM

  • Can't update reader - files in use by adobe 8.1

    I have tried to update to adobe reader x as I cannot view some things online.  My computer runs Vista.
    Error message comes up during installation:  Files in use by Adobe 8.1, close these then retry.   Adobe 8.1 has been deleted from the computer using uninstall and manual deletion.  Still same error message.
    Using the troubleshooting guide, I tried to delete Adobe 8.1 manually.  I tried to delete the files AcroIEHelper.dll, AcroPDF.dll and pdfshell.dll from my computer using command prompt, but computer says access denied.  When I try to remove them just by deleting them out of program files, computer says I do not have permission (although I am administrator).
    Any ideas???
    Thank You

    It means something else on your computer is working with your ipod. Make sure nothing else on your computer is open, and then open i-tunes only, and connect ipod to update.

  • Read files starting with TEST* (for example)

    Hi all,
    Is it possible to read all the files starting with TEST for example from the Unix folder.
    Requirement is there will be files starting with TEST present in the default path x.
    I need to read all the files starting with TEST from this path. So, basically in the selection screen, can I put the default filename as TEST*.
    All these files will have POs(Purchase Orders) which the program needs to update accordingly.
    Please assist.
    Thanks and regards,
    Anishur

    Hi,
    I had to do the same. Selecting all values from table comparing konzs that start with number 500* .
    check the code:
       lv_var = '500'.
       CONCATENATE lv_var '%' INTO h_concern.
       SELECT * INTO TABLE t_lfa1
               FROM        lfa1
               WHERE     konzs LIKE h_concern.
    Adibo.

  • Problem reading file after using webutil_file_transfer.as_to_client

    Hi all,
    The Forms webapplication I'm working on has to talk with a cardreading-application on the client-PC. The communication is carried out by exchanging small files. Reading from the client by Forms on the AS goes well (using client_text_io from webutil). The problem arises when the application has to respond back with a file. The file is made on the AS and then transfered from the AS to the client using webutil_file_transfer.as_to_client. This file can not be read by the cardreading application when the AS is on Linux. Our developement AS server is on a Windows 2000 box and then the communication doesn't show this problem.
    If I open the file from the AS on Linux , I can see that there is only 1 long line. The Windows version of the file contains 2 lines (as it should be). It seems that before/during/after the transfer some special characters like carriage return and tab are causing the problem.
    Looking in web_file_transfer.as_to_client I see that the procedure reads lines from a temporary file into a buffer. The lines are separated by a CHR(10). Could the transfer from Linux to Windows(DOS) cause a problem with these characters ?
    Has anyone experienced this problem ? If someone has a clue this would be very welcome.
    We work with :
    - Forms and AS 10.1.2.0.2
    - Webutil 1.0.6
    - Development OS: Windows 2000 (Service Pack 4)
    - Production OS: Red Hat Enterprise Linux AS release 3 (Taroon Update 3)
    - Client-PC OS: Windows 2000 (Service Pack 4)
    Thanx,
    Enrico

    Without going into a long winded answer, the only thing I can really offer is to say this... If you feel as though your code has been correctly written and you simply cannot identify any other possible solution, add SYNCHRONIZE. In short, its execution acts similar to a reset or refresh button.
    Another common place where SYNCHRONIZE has been helpful is when calling RUN_REPORT_OBJECT. For example, if you use the code we offer in the Forms/Reports Integration document you will find that it works very well - most of the time. However, sometimes it fails for what seems to be unexplainable reasons. If you message out the values being assigned you will see that some variable values are not being set even though the code execution has already passed the point where a value should have been assigned. Adding the SYNCHRONIZE just after the point where the value should have been assigned forces the assignment before executing the next line of code. For example,
         v_rep := RUN_REPORT_OBJECT(repid);
         rep_status := report_object_status(v_rep);
    In the above code, a request for a report is made followed by a check of its status. At this point you would expect that the status would be something like one of the following:
         'RUNNING', 'OPENING_REPORT', 'ENQUEUED'
    However, we have seen instances where the value assigned to the variable would actually be NULL, which of course will make the rest of the code likely fail. By adding SYNCHRONIZE the problem is correctable.
         v_rep := RUN_REPORT_OBJECT(repid);
         rep_status := report_object_status(v_rep);
         SYNCHRONIZE;
    It is important to understand, however that using SYNCHRONIZE comes at a price. Each time it is executed a network round-trip occurs which will give the application the appearance of degraded performance. So use this built-in only when you know you must.

  • Reading file content using Javascript

    Hi Friends,
    is it possibel to read the contents of the child window opened from a javascript.for example am opening a window using Window.open function in javascript, after opening the window can i read the contents ?If so how can anyone help in this.
    Thanks
    Vishy

    Below is the code of my normal java program which works fine.
    try {
    // File destFile = new File("./SourceFiles/savedFile.txt");
    File destFile = new File("./SourceFiles/", "savedFile.txt");
    BufferedWriter writer = new BufferedWriter(new FileWriter(destFile));
    writer.write("TESTing File Save");
    writer.flush();
    System.out.println("SAVED!!");
    } catch ( IOException e ) {
    e.printStackTrace();
    Structure of this project is
    Samples
    |SaveSample
    |SaveSample.java
    |SourceFiles
    |savedFile.txt
    I have implemented similar code in my servlet too. But this doesnt save the content to the HTML file.
    protected void doPost(HttpServletRequest request,
                   HttpServletResponse response) throws ServletException, IOException {
              action = request.getParameter("action");
              try {
    File destFile = new File("./SourceFiles/", "savedFile.html");
    BufferedWriter writer = new BufferedWriter(new FileWriter(destFile));
    writer.write(action);
    writer.flush();
    System.out.println("SAVED!!");
    } catch ( IOException e ) {
    e.printStackTrace();
    Im getting FileNotFound Exception
    java.io.FileNotFoundException: .\SourceFiles\savedFile.html (The system cannot find the path specified)
         at java.io.FileOutputStream.open(Native Method)
         at java.io.FileOutputStream.<init>(Unknown Source)
         at java.io.FileOutputStream.<init>(Unknown Source)
         at java.io.FileWriter.<init>(Unknown Source)
         at savepackage.SaveContent.doPost(SaveContent.java:81)
    Edited by: 849224 on Apr 5, 2011 4:17 AM

  • FM to read files starting with TEST(for example) from Unix server

    Hi all,
    Is there a FM to read all the files which start with TEST (for example) from the Unix server?
    Requirement is if we put TEST* in the selection screen for the filename, it should read all the files which start with TEST from the default Unix path.
    Thanks and regards,
    Anishur

    Function Modules
    http://www.erpgenie.com/abap/functions.htm
    http://www.sapdevelopment.co.uk/fmodules/fmssap.htm
    http://www.erpgenie.com/abap/index.htm
    http://www.geocities.com/victorav15/sapr3/abapfun.html
    Rewards if useful.........
    Minal

  • How to read files from current directory for applet

    I have an applet that needs to read some audio files located in its current directory on the server and I just can't seem to figure it out...maybe I am being dumb...any help?

    You can use the ListSorter File Adapter Configuration property to sort based on timestamp. Basically add the following property to the inbound JCA file:
    <property name="ListSorter"
    value="oracle.tip.adapter.file.inbound.listing.TimestampSorterAscending"/>
    <property name="SingleThreadModel" value="true"/>
    More info see section 4.2.6 in http://docs.oracle.com/cd/E23943_01/integration.1111/e10231/adptr_file.htm

  • File open using Webdynpro for java

    Hi,
    I have a file "SAP.JPEG" in remote machine location "
    SAP\NetWeaver\WebDynpro".
    In my webdynpro application...I have a button and the action "OpenFile"...
    My question is on click of the button, how can I open the file "SAP.JPEG".
    Please advice me how to proceed with this.
    Rgds,
    Patana

    Hi,
    it is possible to access the file from the remote system using webdynpro java. your requirements is quite possible.
    the prerequisites are:
    the SAP WebAS Server and the remote system are in the same network, and the folder (in your case "SAP") is shared folder with access permissions.
    let us assume your remote system name is remSys09.
    add an ui element image in the layout. and create an attribute named "image " bind it to the property source
    use this below code to show the image.
    try {
              File f =new File("////remSys09//SAP//NetWeaver//WebDynpro//SAP.JPEG");
              BufferedInputStream bis= new BufferedInputStream(new FileInputStream(f));
              byte[] image = new byte[bis.available()];
              bis.read(image);
              IWDWebResource webResource = WDWebResource.getWebResource(
              image,
              WDWebResourceType.JPG_IMAGE);
              wdContext.currentContextElement().setImage(webResource.getURL());  
         } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
    Regards,
    Naga

  • How to generate XSL for an XML file to use it for XSLT transformation -SSIS?

    Hi All,
    Can anybody please help me to generate XSL for my attached XML file?
    I need to use the XSL file for XSLT transformation.
    Thanks & Regards,
    Sri

    Hi Vibhav,
    Thanks for the response.
    I am aware of the process but not sure how to generate XSL file. 
    Can you please refer me to any tool which can convert XML to XSL? or please can you transform my simple XML to XSL?
    Thanks & Regards,
    Sri

  • Automating multi-file Flash using XML file "run list"

    I've created a multi-file interactive Flash "demo" for a client. It's very much like a website (though he's not using it as a website) in the way that it is laid out in that there is a main index page which can then direct you to different product categories, which you can click on to see. Each "page" contains product (or product category) information, photos, block diagrams, etc. There is nothing animated in the Flash.
    My client also wants to be able to set it up so that the demo runs automatically from a configurable XML file. My ActionScript skills are pretty limited, but I've been able to using ActionScript 3 to load and read the XML file. Using a 'for' loop, I am able to read the XML file and return the path of each Flash file and the duration that each file should be displayed (my client requested that he be able to configure the duration of each page as well).
    I've set up a loader for each movie clip and a timer for the display duration. Unfortunately, the thing that is throwing me off is that when I attempt to load the movie clip (as the last item in the for loop), it reads the entire XML file, returns all of the clips and durations (I'm using trace to see this) before it loads the movie clip. As a result, the only movie clip that is loaded is the last one read from the XML file.
    As I said, I'm not very good at ActionScript, so everything that I've managed to cobble together has been from internet tutorials.
    This is my code:
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
    var mcLoader:Loader = new Loader();
    mcLoader.contentLoaderInfo.addEventListener(Event.INIT, playClip);
    var mcCurrent:MovieClip = new MovieClip();
    stage.addChild(mcCurrent);
    var xml:XML;
    function playClip(e:Event):void
        trace("Function:playClip");
        stage.removeChild(mcCurrent);
        mcCurrent = MovieClip(mcLoader.content);
        mcLoader.unload();
        stage.addChild(mcCurrent);
    function xmlLoaded(e:Event):void
        trace("Function: xmlLoaded");
        xml = new XML(e.target.data);
        var cl:XMLList = xml.clip;
        for(var i:uint=0; i<cl.length(); i++)
            trace("Begin 'for' loop");
            trace("variable 'i' is" + i);
            var clipPath = cl[i].@path;
            var delay = cl[i].@duration;
            trace("Clip path is " + clipPath);
            trace("Display for " + delay);
            mcLoader.load(new URLRequest(clipPath));
    xmlLoader.load(new URLRequest("filerunlist.xml"));
    I removed the timer event because it, like everything else was getting repeated before anything got loaded, so I wanted to figure out out to get the clip loader (mcLoader) to load the movie clip for each file before I figured out where to put the time to ensure that each clip is displayed for the appropriate duration. I suspect that the timer event needs to occur in the 'playClip' function, but would take advice on that as well.
    Thanks to anyone that can help me figure this out.

    What you need to do in the xml parsing function is to simply store all of the data into an array.  You will then use that array one element after another via whatever timer control you set up, accessing each file in the order they are stored in the array.  You will not do any loading in that function, just data storage, and when you are done, the last line in that function, outside of the loop, will trigger whatever function you have that will start processing the first item in the array.
    Example, storing data objects in the array...
    var clipData:Array = new Array();   // store your xml data here
    var clipToShow:uint = 0;                   // use this later in the showClip function
    function xmlLoaded(e:Event):void
        trace("Function: xmlLoaded");
        xml = new XML(e.target.data);
        var cl:XMLList = xml.clip;
        for(var i:uint=0; i<cl.length(); i++)
            clipArray.push( { clipPath: cl[i].@path, delay: cl[i].@duration } );
        showClip();
    function showClip(){
         // do whatever to process loading clipArray[clipToShow].clipPath
         // and using clipArray[clipToShow].delay for starting whatever timer is involved
         // the timer event handler function will call this function when it is executed
         clipToShow += 1;   // increment the counter for the next clip in line
    If you are not comfortable/familiar with the object approach, then you could also store the clip and delay data in two separate arrays.

Maybe you are looking for

  • Attaching Attributes to Image For Loading to SharePoint Document Library

    We currently have a need to create a searchable document library which will consist solely of images. The standard metadata for a file/image won't suffice in this case. We have some custom attributes that will need to be searchable. Essentially, we w

  • How to do the Record Level commit in DB Adapter

    Hi, I am using Oracle JDeveloper 11.1.1.6.0 and SOA server 11.1.1.6 Problem Description_ I am fetching multiple records using File Adapter in BPEL process, After Fetching I am writing those records in Database using Database Adpter. If any error reco

  • Automation server error 0x800a01ad

    I've been able to batch delete, import, and export metadata from the XML file, but can't seem to import and export the binary thumbnails, raw books, and encrypted books. As soon as I set ImportFiles:Yes and ImportRawBook:Yes, error 0x800a01ad "Automa

  • Bold Rows in SSRS

    Hello, I have a report that has a series of sub totals. Unfortunately, (due to the complexity of the spec) these sub totals are generated within a stored procedure and not as a group total in SSRS. Is there a way that I can highlight/Bold specific ro

  • Worth the money?

    to all it is worth the £9 to upgrade to the latest iPhoto version from v08?