How to check if the content in txt file is empty

hi, i need my program to check if the content in txt file is empty. can anyone demonstrate an example with if-else statement ?

I assume you already have file object
File file = new File("path");
if (file.length() == 0) {
  System.out.println("File size is 0");
else {
  System.out.println("File size is " + file.length());
}Read API here:
http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#length()
Edited by: Kunkhmer on Feb 26, 2008 1:57 PM

Similar Messages

  • How to check whether there r new txt files in a folder n file creation date

    How to check whether there r new text files in a specified folder and what is the date of creation of the text file.........?

    Hi
    I have been searching for a solution to find the date of creation of a file for over 6 months now but haven't found it. So I presume that it is not possible though I havent found any authentication of my assumption in any document.
    Cheers!
    Shailesh

  • How to check on-thy-fly dynamic txt-files

    hello.
    i want to check out a dynamic txt-file (dynamic, because it is a running log from a chat) for specific words.
    the program should start to check the incoming content at the actual end of the file(previous content is in this case uninteresting) and shouldn't stop to do that(unless i want it).
    my problem is, that the program stops after it reachs the end of the file.
    any idea?
    many thx.
    try
              String zeile;
    //Wir lesen aus "eingabe.txt".
              File eingabeDatei = new File(new URI("file:///C:/Log.txt"));
    FileReader eingabeStrom = new FileReader(eingabeDatei);
    BufferedReader eingabe = new BufferedReader(eingabeStrom);
    while ((zeile = eingabe.readLine()) != null)
         Pattern p = Pattern.compile("TESTWORD");
    // Muster: Ziffer, mind. ein Buchstabe, Ziffer
    Matcher m = p.matcher(zeile);
    if (m.find())
         Robot rob = new Robot();
         rob.keyPress( '1' );
    System.out.println (m.group());
         System.out.println("Pattern at Pos. " + m.start());
    System.out.println("Pattern is: " + m.group());
    else
    System.out.println("***No pattern found***");
    //System.out.println(zeile);
    } catch (IOException e)
    e.printStackTrace();
    }

    hello.
    i want to check out a dynamic txt-file (dynamic,
    because it is a running log from a chat) for specific
    words.
    the program should start to check the incoming
    content at the actual end of the file(previous
    content is in this case uninteresting) and shouldn't
    stop to do that(unless i want it).
    my problem is, that the program stops after it reachs
    the end of the file.
    any idea?
    many thx.
    Please use the code tag next time you post code. Thanks.
    (see more comments below)
    try {
         String zeile;
         //Wir lesen aus "eingabe.txt".
         File eingabeDatei = new File(new URI("file:///C:/Log.txt"));
         FileReader eingabeStrom = new FileReader(eingabeDatei);
         BufferedReader eingabe = new BufferedReader(eingabeStrom);
         while ((zeile = eingabe.readLine()) != null)
              Pattern p = Pattern.compile("TESTWORD");
              // Muster: Ziffer, mind. ein Buchstabe, Ziffer
              Matcher m = p.matcher(zeile);
              if (m.find())
                   Robot rob = new Robot();
                   rob.keyPress( '1' );
                   System.out.println (m.group());
                   System.out.println("Pattern at Pos. " + m.start());
                   System.out.println("Pattern is: " + m.group());
              else
                   System.out.println("***No pattern found***");
              //System.out.println(zeile);
    catch (IOException e) {
         e.printStackTrace();
    }The line:
    while ((zeile = eingabe.readLine()) != null)is why your app quits. The while loop ends on null which happens when there is nothing to read from the reader
    From the API:
    Returns:
    A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.

  • Passing the content of txt file to body of Send-MailMessage

    Hi,
    I am trying to send a report using send-mailmessage cmdlet and I am unable to pass the content of the file as it is to body of the message. It gets converted to a single line string (the escape character aren't getting recognized) or body of the mail has
    system.object[] as output.
    Script1:
    $body = Get-Content -Path C:\TEMP\Body.txt | Out-String
    Send-MailMessage -To <toaddress> -Cc <ccaddress> -From <fromaddress> -Subject "$subject" -Body [string]$body -BodyAsHtml -SmtpServer $server
    Error:
    Body of the mail is seen as [string]<content in a continous line>. The actual body in the txt doc is written as we generally write emails
    Script2:
    $body = Get-Content -Path C:\TEMP\Body.txt
    Send-MailMessage -To <toaddress> -Cc <ccaddress> -From <fromaddress> -Subject "$subject" -Body $body -BodyAsHtml -SmtpServer $server
    Error:
    Send-MailMessage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Body'. Specified method is not supported.
    At line:1 char:149
    + ... subject" -Body $body -BodyAsHtml -SmtpServer $server
    +                    ~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.SendMailMessage
    Script3:
    $body = [string]::Join("`r`n",(Get-Content -Path C:\TEMP\Body.txt))
    Send-MailMessage -To <toaddress> -Cc <ccaddress> -From <fromaddress> -Subject "$subject" -Body $body -BodyAsHtml -SmtpServer $server
    Error:
    Send-MailMessage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Body'. Specified method is not supported.
    At line:1 char:149
    + ... subject" -Body $body -BodyAsHtml -SmtpServer $server
    +                    ~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.SendMailMessage
    Thanks in Advance,
    Ankush Shah

    removing the -BodyAsHTML I am getting the below error
    Send-MailMessage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Body'. Specified
    method is not supported.
    At line:1 char:149
    + ... subject" -Body $body -SmtpServer $server
    + ~~~~~
    + CategoryInfo : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.SendMailMessage

  • How to modify/replace the content server(UCM) file/image?

    Hi All,
    I want to modify the content/file of the Oracle UCM server. Do we have any Oracle UCM/IPM's webservice for this?
    For example, content server has a document/file which named as "a.doc". I want to replace this file with "b.doc" without altering any of the meta data.
    Kindly let me know if anybody have a solution for this.
    Thanks in advance!!
    Edited by: 902526 on Mar 20, 2012 1:58 PM
    Edited by: 902526 on Mar 20, 2012 2:02 PM

    Hi All,
    I want to modify the content/file of the Oracle UCM server. Do we have any Oracle UCM/IPM's webservice for this?
    For example, content server has a document/file which named as "a.doc". I want to replace this file with "b.doc" without altering any of the meta data.
    Kindly let me know if anybody have a solution for this.
    Thanks in advance!!
    Edited by: 902526 on Mar 20, 2012 1:58 PM
    Edited by: 902526 on Mar 20, 2012 2:02 PM

  • How to store the content of a file in oracle table.

    Hello,
    I have a .xml file in unix , how can i upload the content of that file into a column of a table in oracle?

    Did you look at the link posted in response to the OP? At a quick look, it seems fairly reasonable to me.
    John

  • How do you see the contents of your "Domain" file?

    Thanks to this forum I have found out that the photo files on my Web site are stored in the Domain file under Application Support. How do you see the contents of this file? When I double-click on it, iWeb launches and I see the actual Web site.
    12" PowerBook   Mac OS X (10.4.8)   G4 1.5 GHz, 768 MB RAM

    i don't think it will work. because when you open up the domain file after you changed the size of the pictures, iWeb will probably save again while uploading - so the changes were for nothing. yet i haven't tried it.
    other way is to change them after you published. using graphic converter you just drag all at once in and change all the sizes at once.
    mp

  • How to check the contents of Control file, Log file & Parameter file

    Can anybody help me how i can check the contents of Control file, Log file & Parameter file.
    Arif

    OK ...
    Parameter file:
    It will normally be in the $ORACLE_HOME/dbs directopry. It could be aan init{sid}.ora or a spfile{sid}.ora ... do not edit an SPFILE as yu could corrupt it.
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14231/create.htm#sthref434
    If it's an init{sid}.ora, use any editor to see the actual content.
    If it's a spfile{sid}.ora, use one of V$PARAMETER, V$PARAMETER2, V$SYSTEM_PARAMETER, V$SYSTEM_PARAMETER2 as aappropriate (read the Reference manual to get an idea about when each is appropriate)
    Control File:
    You should not edit a control file. It consists of many areas, as described here http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14220/physical.htm#i10135 and each are is interrogated by V$views as given in the reference manual. The following V$views all deal with some aspect of the control file or provide info about the control files or the contents of control files:
    V$ARCHIVE_DEST
    V$ARCHIVED_LOG
    V$BACKUP_ARCHIVELOG_DETAILS
    V$BACKUP_CONTROLFILE_DETAILS
    V$BACKUP_CONTROLFILE_SUMMARY
    V$BACKUP_COPY_DETAILS
    V$BACKUP_COPY_SUMMARY
    V$BACKUP_CORRUPTION
    V$BACKUP_DATAFILE
    V$BACKUP_DATAFILE_DETAILS
    V$BACKUP_FILES
    V$BACKUP_PIECE
    V$BACKUP_REDOLOG
    V$BACKUP_SET
    V$BACKUP_SET_DETAILS
    V$BACKUP_SPFILE
    V$CONTROLFILE
    V$CONTROLFILE_RECORD_SECTION
    V$COPY_CORRUPTION
    V$DATABASE
    V$DATABASE_INCARNATION
    V$DATAFILE
    V$DATAFILE_COPY
    V$DATAFILE_HEADER
    V$DELETED_OBJECT
    V$LOCK
    V$LOG
    V$LOG_HISTORY
    V$LOGHIST
    V$OBSOLETE_BACKUP_FILES
    V$OFFLINE_RANGE
    V$PROXY_COPY_DETAILS
    V$PROXY_COPY_SUMMARY
    V$PROXY_DATAFILE
    V$RMAN_BACKUP_JOB_DETAILS
    V$RMAN_BACKUP_SUBJOB_DETAILS
    V$RMAN_CONFIGURATION
    V$SESSION
    V$TABLESPACE
    V$THREAD
    V$UNUSABLE_BACKUPFILE_DETAILS
    3) Log Files
    The contents of the log files are viewed using LogMiner - read Chapter 11 of the Oracle Utilities manual

  • How can i compare the contents of two folders ?

    how can i compare the contents of two folders and find out which files are in one but not in the other?? Knowing how to do this would be the best thing ever, especially when dealing with a large number of files. Often, for instance, I'm dealing with a large number of images, processing them, and saving the retouched ones to a new folder, and need to check that they are all there. If there are say three files missing in the second folder (out of say a hundred in total) being able to automate the process of elimination would be very useful. Please help!!!
    B

    I really wish I knew the answer to this. I work between two macs, a G5 and MacBook Pro when I'm on the go. Each time I move from one to the other I have to copy all my files to the computer I'm going to work on, so I end up with the same files being duplicated. It's not a problem if it's not much data but in my case the it can be to 30GB, mostly graphics files, photoshop, motion, final cut pro, etc.
    There's has got to be a way automator can make a comparison between two folders to sort out what's changed and what's remained the same. It would be nice also if this feature could be done globally on the hard disk using spotlight's technology to stop files being duplicated in places you didn't even know about and taking up valuable disk space. I'm not sure how this could be done.
    Any bright ideas Apple?

  • How to check, when the Maintenance Order was deleted

    Hello Experts,
                          Can you please tell me of how to check for the maintenance order that when it was deleted and who has deleted that.
    If any T-Code is there or at the Table level also to check the requirement.
    Regards,
    Yawar Khan

    If you want to track when you have put deletion flag, you can track it using above mentioned techniques.
    If you archived (deleted) permanently, then using archival history only, you can check I guess.
    Check these links. While deleting maintenance order, we can hisorical order with same number. Using that creation date, you can track.
    http://help.sap.com/saphelp_nw04/helpdata/en/8d/3e6552462a11d189000000e8323d3a/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/8d/3e4d2f462a11d189000000e8323d3a/frameset.htm

  • How to check whether the Application Server directory exits or not

    Hi,
    I have a selection screen in which I give the Application server file name(UNIX file) as input. Here, I would like to check whether the Server directory exists or not.
    Let us say, the path I gave in the selection screen is /usr/sap/tmp/testfile.txt . Here, the file name is testfile.txt and the server directory is /usr/sap/tmp . I would like to check whether this directory /usr/sap/tmp exists in the server or not. I am not bothered about the file name as I am going to write data into the file. I am mainly concerned about whether the directory exists in the server or not. and one more thing... this is the Application Server path not the Local path.
    Can anyone help me on the same how to check whether the server directory exists or not.
    Thanks in advance.
    Best Regards,
    Pradeep.

    Also you can use the FM EPS_GET_DIRECTORY_LISTING for this purpose.
      Store the directory name
        l_dpath = p_file+0(l_no).
      Validate the directory of the application server
        CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
          EXPORTING
            dir_name               = l_dpath
          TABLES
            dir_list               = l_i_dlist
          EXCEPTIONS
            invalid_eps_subdir     = 1
            sapgparam_failed       = 2
            build_directory_failed = 3
            no_authorization       = 4
            read_directory_failed  = 5
            too_many_read_errors   = 6
            empty_directory_list   = 7
            OTHERS                 = 8.
      If any problem occurs with the directory then display proper
      error message
        IF sy-subrc <> 0.
        Display error message
          MESSAGE e018 WITH 'Problem with directory entered'(008).
        ENDIF. " sy-subrc <> 0
    Regards,
    Joy.

  • How to Check when the user is connected to different desktop.

    How to Check when the user is connected to different desktop.Sometimes the user maynot see the theme in the personalize theme list. In that case the person must be using different kind of desktop.How to check, I need a path.And how to apply the theme to that user?
    Thanks,
    Paturi

    Hi,
    you can create the new portal desktop from
    System Administration => Portal display => Desktop and Display Themes
    Select your folder from Portal Content and from its context create new Desktop.
    Add The Framework page and the theme to this desktop page.
    Go to your folder from Portal Content and from the context of the framework page select add framework page to portal desktop.
    Adding Theme to desktop
    From Portal content select Theme folder and select the theme right click it and select Add theme to Portal Desktop.
    Create rule for the Desktop.
    Navigate to System Administration => Portal Display => Desktop and Display Themes Portal Content => Portal Administrators => Super Administrators =>main_rules.
    Click Add IF Expression.
    create the expression if user = xyz then click on apply
    Select the then clause of the if and navigate to your folder where Desktop is created ,Add it and Click Apply.
    Save the Changes to the rule.
    Hope it helps you.
    (reward points if its helpful)
    Thanks,
    Gunjan

  • How to read the contents of XML file from my java code

    All,
    I created an rtf report for one of my EBS reports. Now I want to email this report to several people. Using Tim's blog I implemented the email part. I am sending emails to myself based on the USERID logic.
    However I want to email to different people other then me. My email addresses are in the XML file.
    From the java program which sends the email, how can I read the fields from XML file. If any one has done this, Please point me to the right examples.
    Please let me know if there are any exmaples/BLOG's which explain how to do this(basically read the contents of XML file in the Java program).
    Thank You,
    Padma

    Ike,
    Do you have a sample. I am searched so much in this forum for samples. I looked on SAX Parser. I did not find any samples.
    Please help me.
    Thank you for your posting.
    Padma.

  • How can i get the content of JTextArea with out loosing Indentation.

    I am developing one mail sending application. I am getting mailid , from address, mail body from one Swing. In one JTextArea i am typing i have typed some matter. When i call the content of JTextArea using
    jtx.getText() method, i am getting all the content as one paragraph. That means there is no indentation which was there in TextArea.
    Please provide me some solution how can i get the content of JTextArea wiht out loosing indentation.

    And it was you who asked the question!

  • R12.1.1 staging complete! How to check whether the stage is Good

    Hi Gurusl,
    I have completed staging R12.1.1 for Hp unix B.11.31. I want to know how to check whether the stage is good for installation or whether it is corrupted. Is there any metalink note or script from where we can check it. Ur help will be highly appreciated. Thanks in advance
    regards,

    Hi,
    Please refer to (Note: 802195.1 - MD5 Checksums for R12.1.1 Rapid Install Media).
    Regards,
    Hussein

Maybe you are looking for

  • Where are the Mail files located?

    Can some one guide me to the location of the mail boxes, files on my hard drive so that I can back them up. I could do this with outlook, entourage but unable to find those files with Mail.app. MacBook 10.5.1

  • Apache - Weblogic plug-in - Segmentation fault. Please Help me!

    Hi all, Im trying to set up Apache weblogic plug-in, and im having problems with that. Im running Solaris 9 with Apache/1.3.26 (Unix) and Weblogic 7 with sp2. Here is what i did: I copied mod_wl_ssl.so from /bea/weblogic700/server/lib/solaris/mod_wl_

  • Invalid combinations of joins involving outer joins

    Hi all, I have the following problem Scenario: I created 6 custom folders: Tasks (with measures) Type Criticity Status Owners Assignees The first folder is used to retrieve how many tasks (COUNT(tasks)) have a particular type or status or a combinati

  • SAP industrial solution for Mining (IS-Mining)

    Dear Experts, I believe that SAP has industrial solution for Mining (IS-Mining). Do they have BW analytics / Reports for the IS-Mining ? Appreciate an early response. Thnx n Rgrds Mohan Edited by: Mohan Kumar on Nov 4, 2008 7:39 AM Edited by: Siegfri

  • LOV error: correct set up?

    Hi, I'm new to Oracle Forms and LOV's. From what I can tell I created one correctly but am coming up with an error. Hope someone can help. I can connect with no errors. I'm on Oracle Forms 10g, connecting to Oracle 10g database. I created a record gr