Importing and sorting text file

I am importing a text file. Now i need to run and if function, so I can sort the text data between positive and negatives.
import java.util.Scanner;               //Needed for Scanner Class
import java.io.*;                              // Java API Class that allows you to import files
The Transactions.java program was designed to import text file (transactions, sort
the data with values of "<= 0" and ">=1" as withdrawals and deposits respectively.
Then the program will output the data into two different text files: Deposits.txt
and Withdrawals.txt.
public class Transactions
public static void main (String[] args) throws IOException
String display = "test";
     //Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
     //Get the file name.
System.out.print("Please enter the name of the file you are trying to acces:");
String filename = keyboard.nextLine();
     //Open the file.
File file = new File(filename);
Scanner inputFile = new Scanner(file);
          //Read lines from the file until none are left.
while (inputFile.hasNext())
          //Close the file
inputFile.close();
}

euvin wrote:
the program will call a text file. the text file has a range of numbers. from negative to positives. i can get the program to import the data; however, i need these data to be sorted by <= 0 & >= 1When you read the lines from the text file they will be read as Strings. You will need to parse those Strings to a number (Integer or Float/Double depending on if the numbers are whole numbers or decimals). The Double and Integer API pages give you the methods you need to use to convert the String to the correct number.
Edited by: amp88 on Feb 16, 2009 7:28 AM

Similar Messages

  • Is it possible to import a Fixed Text file that does not have a header?

    I'm trying to import a Fixed Text file through Import Manager, but the text file I am receiving does not have a header on it (the first row is valid data). When I try importing this, Import Manager uses the first row of data as the headings. Is there any way to turn this off and tell Import Manager there is no header data in the file?
    Thanks!

    Hi Ryan ,ur requirement can be met only when u import the file as ODBC .for this follow the below steps.
    1)Go to control panel,in ur settings,select administrative tools
    2) In that select DATA SOURCE(ODBC ).
    3)Go to SYSTEM DSN tab select tab .
    4)Select ur file type MICROSOFT TEST DRIVER (.txt,.csv)
    5)Double click on "Import DSN" and in the blank give the name of DATA SOURCE NAME any name u want to give.
    6)Uncheck the use current directory box and select the directory ur file is it will automatically show ur source file select it and click ok.
    7) Now when u import ur file as ODBC give the name of ur DATA source name which u have given and it will show ur file in the source preview itself .
    In  this way u can import ur file as ODBC.
    Hope this may help u.
    Regards
    Ankit

  • Read and write from and to text file

     Hi All,
    I am trying to read some portion of a text file and make measurement and calculation with those numbers and write back to the same text file and also to a excel file. I need to create a 2 D  array of 20 by 20 from the text file values and write to front panel table and to text file. but I am having problem with it, obviously I am new to this. Please help me.  thanks much
    ~ Johnny

    Hi Lynn,
    the requirement is to move C1 and C2 to each position that is given in the text file in steps and percentage value.
    for example C1 has to go to first step (5%) and C2 has to go thru all steps, 5% to 95% , in 5 percent increment. 
    each 100 steps translates to 1 percent increment in the capacitor value.
    at the end, I need to enter the measured data (values of C1 for each step, vesus all values of C2 for all steps) and enter them at the bottom of the text file's table where it starts at : "IMPEDANCE_REAL in Ohmone line per C1 position, containing all values for the different C2 positions" and do the same for where it says "IMPEDANCE_IMAGINARY in Ohmone line per C1 position, containing all values for the different C2 positions"
    the reason I read the file twice, is that if it read it once, I couldn't connect it to spreadsheet string to array vi.
    as you can see, I also like to use the write to measurement file and build table express vi's to display the table on the front panel and save the data to ni data file format so later I convert it to excel  too.
    any thoughts?
    thanks for your help
    ~ Johnny
    Attachments:
    read from text2.vi ‏82 KB

  • Can I save and read text files on a server that I host?

    Hello everyone,
    I am a java hobbiest. I was wondering if I set up my own server, running out of my house, could I have my applets save to my computer and read from my computer without having to learn JDBC and a DATABASE language. In other words could i just have my applet save and read text files from and to my server?
    I'm trying to set up a sight for my 5th grade class where parents can log into. Thanks for your time.
    Oh yeah, which is easier, learning how to set up a server or learning JDBC and a DATABASE language?
    If you have any other good idease please tell me them
    Thank you, Bryan

    Short answer: This isn't gonna work
    Long answer: For this to work, the first thing you're going to need is a static IP address and a DNS name registered -actually you don't necessarily need #2 but you're probably gonna want it and it's by far the easier of the steps.
    As far as I know to get a fixed IP address you've either gotta be directly attached to a larger network (ie university network) or get a leased line from an ISP.
    Once you've got that done come back to us.

  • How can u insert and retrieve text files in any format using forms6i.

    how can u insert and retrieve text files in any format using forms6i.
    can u give me an example of an insert statement, let's assume the file is located in the a:drive.
    and retrieving the files, i would give the user a list of all the files that are in the database, the user would select one, but what command(or piece of code) would open the file in its apppropriate editor.
    e.g .pdf formatted file would open in acrobat.
    any help would be appreciated.
    Thanks
    Hussein Saiger

    the filereference class is for downloading and uploading files.
    if you want to load xml, use the xml class.
    and, if you want to write to an xml file and don't want to use server-side code, wait.

  • SoD Risk Summary and Rule Text Files for CC 5.1

    Hi,
    Could anyone share with me where could I find the SoD Risk Summary and Rule Text Files for CC 5.1? I have looked into SAP Marketplace but I was not able to find such information. In the installation files we downloaded, these files are not included either
    Thanks in advance. Regards,
        Imanol

    Hi,
    These rules were available on the market place for CC 40: they were included in the support package 1 or 2.
    For CC 51, we had the same issue as you: we did not find the rules on the market place. Apparently, they are not.
    My customer had to send a OSS message to SAP in order to receive the rules (.txt files).
    Regards,
    Nicolas.

  • How to create and read text file using LabVIEW 7.1 PDA module?

    How to create and read text file using LabVIEW 7.1 PDA module? I can not create a text file and read it.
    I attach my code here.
    Attachments:
    File_IO.vi ‏82 KB

    Well my acquisition code runs perfect. The problem is reading it. I can't seem to read my data no matter what I do. My data gets saved as a string using the array to string vi but I've read that the string to array vi (which I need to convert back to array to read my data) does not work on the pda. I'm using version 8.0. So I was trying to modify the program posted in this discussion so that it would save data from my DAQ. I did that but I still can't read the data after its saved. I really don't know what else to do. All I need to do is read the data on the pda itself. I can't understand why I'm having such a hard time doing that. I found a possible solution on another discussion that talks about parsing the strings because of the bug in the "string to array" vi. However, that lead me to another problem because for some reason, the array indicators or graphs don't function on the pda. When i build the program to the pda or emulator, the array indicators are faded out on the front panel as if the function is not valid. Does this kind of help give a better picture of what I'm trying to do. Simply read data back. Thanks.

  • Can I import and open raw files on the new photo app?

    Hi,
    Can I import and open raw files on the new photos app on my ipad?  Does it convert it to jpeg automatically when you want to share them?
    Thanks.

    Clem is telling you to click on the View menu, move the pointer down to the item "Metadata," & from its choices make sure "Show Titles" is selected. Do this, then make sure you are in a view in the main window that shows one or more videos (or whatever) that you want to title. Click once on one of them, & if the separate Info window is not open, open that (on the Windows menu or command + i as a keyboard shortcut). In the Info window the top line will be "Add a Title."
    Click once on that & type your title.
    This works for any item, video or photo.

  • HT4641 , I'm currently using apach, open office on my laptop, will I be able to import and edit these files using Pages??? Thanks in advance.

    , I'm currently using apach, open office on my laptop, will I be able to import and edit these files using Pages??? Thanks in advance.

    Yes, as long as you save them in .doc format.

  • Import data form text files

    I wish to import multiple text files into one table in SQL Server 2008 but I don't have SSIS
    capability. I wish for the format of the file to stay the same (no formatting or modification of data) and I wish for each file to be dumped into its own row under one column heading (e.g. 'Data')

    Please use BULK INSERT to bring the text files into a SQL table...but you have to know the layout of the data, and create destination table
    (whether it's a "staging" table or the real table) before you do anything else.you also need to know how the file is delimtied...comma delimited , tab delimited, or fixed width, or some custom delimiter. Sample :
    BULK INSERT MULTIPLE FILE
    -a table to loop thru filenames drop table ALLFILENAMES
    CREATE TABLE ALLFILENAMES(WHICHPATH VARCHAR(255),WHICHFILE varchar(255))
    --the source table: yours already exists, but needed for this example.
    CREATE TABLE BULKACT(RAWDATA VARCHAR (8000))
    --some variables
    declare @filename varchar(255),
    @path varchar(255),
    @sql varchar(8000),
    @cmd varchar(1000)
    --get the list of files to process:
    SET @path = 'C:\DB\'
    SET @cmd = 'dir ' + @path + '*.txt /b'
    INSERT INTO ALLFILENAMES(WHICHFILE)
    EXEC Master..xp_cmdShell @cmd
    UPDATE ALLFILENAMES SET WHICHPATH = @path where WHICHPATH is null
    SET @path = 'C:\DB2\'
    SET @cmd = 'dir ' + @path + '*.txt /b'
    INSERT INTO ALLFILENAMES(WHICHFILE)
    EXEC Master..xp_cmdShell @cmd
    UPDATE ALLFILENAMES SET WHICHPATH = @path where WHICHPATH is null
    SET @path = 'C:\DB3\'
    SET @cmd = 'dir ' + @path + '*.txt /b'
    INSERT INTO ALLFILENAMES(WHICHFILE)
    EXEC Master..xp_cmdShell @cmd
    UPDATE ALLFILENAMES SET WHICHPATH = @path where WHICHPATH is null
    SET @path = 'C:\DB4\'
    SET @cmd = 'dir ' + @path + '*.txt /b'
    INSERT INTO ALLFILENAMES(WHICHFILE)
    EXEC Master..xp_cmdShell @cmd
    UPDATE ALLFILENAMES SET WHICHPATH = @path where WHICHPATH is null
    --cursor loop
    declare c1 cursor for SELECT WHICHPATH,WHICHFILE FROM ALLFILENAMES where WHICHFILE like '%.txt%'
    open c1
    fetch next from c1 into @path,@filename
    While @@fetch_status <> -1
    begin
    --bulk insert won't take a variable name, so make a sql and execute it instead:
    set @sql = 'BULK INSERT BULKACT FROM ''' + @path + @filename + ''' '
    + ' WITH (
    DATAFILETYPE = ''char'',
    FIELDTERMINATOR = ''||||'',
    ROWTERMINATOR = ''\n'',
    FIRSTROW = 1
    print @sql
    exec (@sql)
    fetch next from c1 into @path,@filename
    end
    close c1
    deallocate c1
    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

  • Import data from text file

    We are trying to import data from a text file into fields in a form using the importTextData method for the Doc object. The script we are using looks like this:
    var doc = event.target;
    var returnCode = doc.importTextData("datafile.txt",0);
    The text file "datafile.txt" contains tab separated values in a header row (which corresonds to field names in the form) followed by tab separated datarows - all according to instructions in the API.
    The returnCode will result in an integer value, which in our case represent "Error: Invalid Row". It would help us a lot if anyone could give us a hint on what may be wrong or even better post a working solution.
    We have also tried using the importTextData method without any parameters (the user is then prompted to select the text file and then the specific row) but the result remains the same. The fields in the form are not populated with data and the message "Error: Invalid Row" is returned.
    Annika Lindqvist

    The problem you're experiencing is that importTextData is an Acrobat API call. As such, it executes on the AcroForm field equivalents to the XFA fields you've placed on the form. What's not indicated in the API for importTextData is that the names in the fields in the header of the text file must be the
    full AcroForm SOM expression.
    I've created a working sample to explain this.
    First, I created a form with a table with one row in it containing 3 columns named FirstName, LastName and Country.
    Then I created a data.txt file like this:
    FirstName LastName Country
    Fred Jones USA
    Kyle Francis Canada
    Sam Roberts UK
    I then placed a button on the form which calls "event.target.importTextData();" and ran the form in Preview.
    Of course, when I selected a row for import, nothing happened.
    I then used the "Avanced | Forms | Export Data from Form..." menu option in Acrobat after filling-in the fields in the table with some text and looked at the generated text file (note that you have to specify text as the output format). In there, I was able to figure-out what the full AcroFrom SOM expression was for each field I wanted to import data into.
    I changed my data file to look like this:
    form1[0].#subform[0].Table1[0].Row1[0].FirstName[0] form1[0].#subform[0].Table1[0].Row1[0].LastName[0] form1[0].#subform[0].Table1[0].Row1[0].Country[0]
    Fred Jones USA
    Kyle Francis Canada
    Sam Roberts UK
    Afther that, importTextData worked as expected without any errors.
    Stefan
    Adobe Systems

  • Import a CSV text file into SQL Server using DTS

    Hi,
    This may be a silly question but im gonna ask it anyway!
    What i need to do is execute a DTS package from a CF page to read a text file and import its content to a table. I have 100's of txt files with 10,000's of rows.
    The reason i think this is a silly question is because when setting the DTS package in SQL Ent, you have to specify the file name of the file you wish to import data from, therefore, its possible that you cannot change the file name. Ive done lots of research and not found one example that will allow me to do dynamically change the file name making the DTS pick up a different file. The only code ive found is as below, that executes the DTS and imports the data obtained from the file name that was set when the DTS package was created.
    <cfobject
    type="COM" name="objDTS" class="DTS.Package" action="CREATE">
    <CFSET
    r = objDTS.LoadfromSQLServer("[SERVERNAME]","[PASSWORD]","",0,"","","","[DTSPACKAGE]","")>
    <cfset
    p = objDTS.Execute()>
    I found the following suggestion in a forum somewhere, but ive not had much luck with it
    <cfset
    objDTS.GlobalVariables.Item("filename").Value = "[statsFileName]">
    I know an alternative to this is to read the file using CFfile or using Java and insert one by one, i dont dont like that method as it could cause performance issues with my server.
    Hope someone can help me out.
    regards
    d

    Questions:
    1. What version of SQL Server are you using?
    2. Are you required to use a specific DTS package or do you simply need to import data from a file to a table?  You might also consider using the bcp utility or, if you are using 2005 or newer, integration services.
    3. Is the uploading of files and the import of data a manual process or is it automated?  Is there a user uploading one file at a time to your server or do you receive files in batches.  Can you describe the work flow?
    You might try the following if you are required to use DTS:
    1. Upload your text file with CFFILE, putting in the directory expected by your DTS package.
    2. Rename the file to the name required by your DTS package
    3. Use CFEXECUTE to run the DTS package by calling dtsrun at the command line.
    dtsrun
    http://msdn.microsoft.com/en-us/library/aa224467%28SQL.80%29.aspx
    bcp
    http://msdn.microsoft.com/en-us/library/aa174646%28SQL.80%29.aspx

  • How to export report to excel and to text file in previewer

    How to export report to excel?
    And, it takes long time for generate report to rtf or pdf file in previewer.
    How to speed up the process? or, it's better generate report to text file directly by Run_product?
    Please help!

    You can generate report to tab delimite format that can be imported to excel.
    As for the performance question, because reports can't specify what format when you run against previewer, so I don't know what previewer you are talking about. Generate to file is always faster than to your application previewer (assume) because you have one more step after output generated in the file: read from file and render it. Depends on the render and size of the output, it may have significant performance difference.
    Thanks,
    -Shaun

  • Importing and organizing photo files lightroom 5 for the first time. Clean up hard drive photo files

    I have a trial version of lightroom 5 and would like once and forall to bring some order to both my hard drives and lightroom 5 collection. Some photos in lightroom 5 seem to have lost their path. some are in Window 7 folders and others are in Elements 9. I have made back up copies of some folders and would like to have a more systematic approach to back them up from now on. I have a NAS (network access storage) device and an extra hard drive I thought it would be best to use my laptop as the primary working memory for my photo files as it would be faster than working with the NAS or external, and then back everything up to the NAS and external. I see the main challenge as  consolidating all of the files and whereever possible preserving the ratings I have given photos; I would like to eliminate duplicats. on both the hard drive and in lightroom. i have looked at one of the initial training vidios on the 'library' section of adobe help and the presenter talked of two methods of importing photos,. the first and the one I think I will use going forward is to open lightroom and import from the sd card directly as opposed to having Windows 7 import and then having lightroom find them. If someone kows of a comprehensive list of instructions to follow to clean up my hard drives that would be extremly helpful? Peter

    I doubt there is a list of instructions to clean up a hard drive, because every starting sitaution is different, and your "clean" is probably a lot different than my "clean".
    But let's clear up a few things first. Based on your writing, it seems like you think you have photos stored in PSE and photos stored in LR. This is not correct. Neither of these programs store your photos. All of your photos are on your hard disk, in folders, somewhere.
    With regards to missing photos in Lightroom, when you move or rename photos and folders OUTSIDE of Lightroom, Lightroom no longer knows where they are, and reports them as missing. To fix it, see: http://www.computer-darkroom.com/lr2_find_folder/find-folder.htm Related to this, you don't want to "clean up" things in Windows and also "clean things" up in Lightroom. Instead, once you import photos into Lightroom, you should do all photo management in Lightroom, not Windows, otherwise you will just be creating more missing files.
    With regards to duplicates, Lightroom has some tools to detect duplicates. It will try to prevent duplicates on import, and if you do manage to import duplicates, you can use the "AutoStack by Capture Time" to try to find additional duplicates. But if those don't work, then you're pretty much on your own.
    With regards to putting photos on your laptop to work on them rather than your external HD, I think you will find that this provides a tiny fraction of a second improvement in speed which you may not even notice, which will be offset by the time you spend moving photos to somewhere else when you are done. So, just put the photos in their final destination folder on your external HD or NAS, and don't bother moving them to the internal HD.
    Which brings up another point. Once you have accomplished this "clean up", your workflow should be to put the photos in one place, and then don't move them! (Exception: running out of space on disk, or moving to a new disk/computer) Make your life as simple as possible.
    One last point: strongly consider using keywords and other metadata to achieve organization, instead of moving photos/folders from here to there to achieve organization. These tools in Lightroom give you ability to organize in much more powerful and flexible organization than anything you can do by moving photos/folders from here to there. (Side note: if you want all photos in some sort of centralized location because it meets your storage needs, then do that because it meets your storage needs. Within that collection of photos in a centralized location, use keywords and other metadata to achieve organization and for searching)

  • Import and read a file in AS3

    Using AS3, I want to extracte data from a file to fill in my arrays.
    I would like to do this without using php and server side coding
    all done in AS3
    the file can be a spread sheet
    thx in advance

    It works vey well for text files. I tried it with the code below
    Now to read excel spread instead of text, what it the easiest way or fastet way?
    Thanks in advance
    package{
        import flash.net.URLLoader;
        import flash.net.URLRequest;
        import flash.display.MovieClip;
        import flash.events.Event;
        public class ReadFile extends MovieClip {
                var urlLDR:URLLoader;
                var urlR:URLRequest;
            public function ReadFile ():void
            { init();}
            public function init ():void {
                urlLDR = new URLLoader();
                urlR = new URLRequest("Test.txt");
    //urlR = new URLRequest("Test.xls");
                urlLDR.addEventListener(Event.COMPLETE,f);
                urlLDR.load(urlR);
            function f(e:Event){
                trace(e.target.data);
        }//class
    }//package

Maybe you are looking for