How to test if file is  empty???

I have written a program that reads from a text file.
How do i check that the file is empty,stop reading and display
an error message?
Here is the code i have.
try
      { FileReader in = new FileReader(fileName);
        BufferedReader reading= new BufferedReader(in);
        while (reading.ready())
        { StringTokenizer st = new StringTokenizer(reading.readLine());
          try
          { int k = Integer.parseInt(st.nextToken());
            /*I've tried this way but keep getting error
            if(k==null)
            { JOptionPane.showMessageDialog(null,
                            fileName+" is empty","Empty File",
                            JOptionPane.ERROR_MESSAGE );
              return;
            if(k>100)
               return;
            else
             Content[k].setText(st.nextToken());
          catch ( NumberFormatException nfe )
          { JOptionPane.showMessageDialog(null,
                            "All the addresses in file "+fileName+
                            " Must be integers","Invalid Address Format",
                            JOptionPane.ERROR_MESSAGE );
            return;
        for(int i=0;i<Content.length;i++)
        { Content.setEditable(false);
in.close();
catch ( IOException e )
{ JOptionPane.showMessageDialog( null,
"Error Opening File", "Error",
JOptionPane.ERROR_MESSAGE );

simply call File.length() on the file which returns a long with the number of bytes in the file...if 0, it's empty. Of course, if there are control codes (like \n or \t and nothing else in it) it won't be 0 bytes long but you would probably consider that empty too...so you must code accordingly.

Similar Messages

  • How to test HTTP file?

    Hi all,
    I have a simple senario to test HTTP file.
    I want HTTP file to be written into XI as a file.
    Can anyone tell me the steps involved in this?
    I have created a HTTP service as sender with HTTP as communication channel, sender message interface.
    Is there anything I have to fill in receiver tab?
    I have the XI as business system receiver with file communication channnel.
    How about the sender message interface for HTTP, should it be ASYNC, ABSTRACT?
    I created the receiver determination, interface determination, receiver agreement.
    Am I missing anything?
    I appreciate your response.
    Regards,
    felix.

    Hi Stefan, I configured the way you have put it, but I get the error "no receiver could be determined"
    Here are my settings:
    Sender service - HTTP_SEND
    sender o/b interface - PROD_MSG_INT_OB_ASYNC
    receiver service - FILE_RECEIVE
    receiver i/b interface - PROD_MSG_INT_IB_ASYNC
    receiver communication channel - FILE adapter
    JAVA script:
    String Party       = "MFC";
    String Service     = "HTTP_SEND";
    String XINameSpace = "mfc%3Anamespace1";
    String Interface   = "PROD_MSG_INT_OB_ASYNC";
    String Url   = "http://nemo:8000/sap/xi/adapter_plain?";
    XML DATA File:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:PRODUCT xmlns:ns0="mfc:namespace1">
    <ID>E</ID>
    <NAME>thank god</NAME>
    <BRAND>SOME BRAND</BRAND>
    </ns0:PRODUCT>
    Stefan Am I missing anything?
    XML error message:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Receiver Identification
      -->
    - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
      <SAP:Category>XIServer</SAP:Category>
      <SAP:Code area="RCVR_DETERMINATION">NO_RECEIVER_CASE_BE</SAP:Code>
      <SAP:P1 />
      <SAP:P2 />
      <SAP:P3 />
      <SAP:P4 />
      <SAP:AdditionalText />
      <SAP:ApplicationFaultMessage namespace="" />
      <SAP:Stack>No receiver could be determined</SAP:Stack>
      <SAP:Retry>N</SAP:Retry>
      </SAP:Error>
    It would be great if you have solution for this.
    Regards
    felix

  • How to test 1099 file format ( IRS )

    Hi all,
    We are on ECC6.00 .
      We need to submit 1099 file t IRS department. How to confirm if the file generated by SAP is in correct format as specified by IRS.  Its become problematic after you send the file to IRS and they come back with formatting issue .
    Is there any software available ?
    Best Regards

    hari
    You can send the test file using the same IRS portal that you use for submitting the real file. You will then receive an email from IRS telling you the exact formatting error or if the file has passed. IRS will allow the test files only during specific period in a year (normally Nov-Jan).
    Thanks
    Ron
    Edited by: Ron on Jun 14, 2011 7:11 PM

  • How to restore photo file after empty trash

    photos file have been deleted and trash is empty.  please advise how to restore. many thx! cheers

    Hey there TizJacky,
    If I understand correctly there were pictures in your Mac OS trash which has been emptied, and want to restore them. In order to do this, you would need to have had Time Machine setup and backing up your computer before this occurred. This article will help you out if you did:
    Mac Basics: Time Machine backs up your Mac
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • How to test SCA file?

    Hi
    I have an SCA file named aneAZANW_AZLB_C~20060529092256.sca containing webdynpro development components.
    help.sap.com says:
    <i>"You have imported the SCA successfully into the test system. It has been deployed in the test J2EE Engine.
    Now test the application by running the servlet in the browser under the URL http://<host>:<port>/contextRoot/tax.jsp."</i>
    But this is for the specific java tutorial.
    My SCA file has been deployed onto the test j2ee engine.
    How do I test the application?
    Thanks
    Manoj

    Hi Manoj,
    Since your application is Webdynpro you will need the URL for your webdynpro app. Or you can login to Wendynpro Content Administrator of your test system and run the application from there.
    Regards
    Sidharth

  • How can I restore files from empty trash?

    Please someone help me! I deleted my IPHOTO LIBRARY by mistake, and then I pressed " empty trash". Is it even possible for me to recover deleted itens from the trash? I live in Brazil and the closest Apple Store is 5 hours from home. I am not that comfortable with any support companies trying to fix my computer and I can't set up Time Machine alone.
    Any tips?

    I have heard of it, I know nothig about it, Data Rescue is the one I see recommended the most. I had to use Data Rescue once many years ago on a family members machine and recovered quite a bit, but it was a purchased version.
    Try the Wondershare and see if it finds anything (what have you got to lose? as of now you have already lost data) I would try the trial version and see if it recovers anything before thinking about buying the full package.If it does not recover anything then I would not buy it. Maybe then you might try the Data Rescue 3 trial and seee if that recovers anything.
    As for Time Machine back up, you REALLY want to have that on an external drive.You can partition your internal drive for a Time Machine back up, but what happens if the internal drive crashes,? Then you have nothing. With an external Time Machine drive you can replace the broken drive and then restore the data.
    I have 2 back ups 1 Time Machine, and 1 Carbon Copy Clone (the CCC can be booted from, so if my internal drive goes down, I can still start up from the clone. Drives are fairly inexpensive these days, data can be pricless.
    It is not a question of if my drive will crash, it is a question of when, all drives will fail at some point.
    By the way, your english is quite good.
    I hope this helps and you get your photos back, I would be very sad if I lost all of mine.
    Best of luck

  • How to test if particular character is empty in a row

    Hi All ,
    Requirement : To split the input file into two files .
    If the length of the row is 93 characters and the condition is If characters from 28 to 32 are empty then create a file with the name PCO1 .txt else create a file with the name PCO2 .txt
    Please let me know how to test in a row if particular character has certain value or from 28 to 32 are empty .
    Thanks for your help

    hi Sharma,
    IF line+27(5) EQ space.
    ==> positions 28-32 have no value (i. e. all characters are spaces)
    ELSE.
    ==> positions 28-32 have some value
    ENDIF.
    some explanation:
    line+27(5) ==> this means: 5 characters after position 27
    hope this helps
    ec

  • How to test File Adapter from EM Console

    Hi All,
    I have one issue with File Adapter where I am trying to implement a simple BPEL process. Below are the steps;
    1. I have created an empty BPEL process and then add a read file adapter to the left side which will read from a file aa.txt which is present in D:\work folder. File is having data like XXXX,YYYY,ZZZZ. (I have used Native builder for schema generation)
    2. Then I have added Write file adapter on the right side which will write to an other file bb.txt.
    Then I have rebuild and deploy this on weblogic SOA server but on the EM console I am not able to test it as Test button is disabled. Then how to test this scenario? Also I tried testing by placing a new file aa1.txt in the same directory with some content. Logically it should be picked up and then write it to the bb.txt but it is not happening.
    Can anyone please help me in this as how to troubleshoot it.
    Thanks
    RJ

    Thanks for the reply.
    So if i understood correctly it means that we cannot test it using EM console as we have read adapter on the left side because of which we have not exposed it as SOAP service. When we put any file in the D:\XXX then automatically read adapter will pick that up and create one instance in the EM console and then write adapter will write it into the destination file?
    But in our case no instance is getting created in the EM console even when I am copying a file to the directory. Below is the read_file.jca
    <adapter-config name="Read" adapter="File Adapter" wsdlLocation="Read.wsdl" xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
    <connection-factory location="eis/FileAdapter" UIincludeWildcard="rj*.txt"/>
    <endpoint-activation portType="Read_ptt" operation="Read">
    <activation-spec className="oracle.tip.adapter.file.inbound.FileActivationSpec">
    <property name="DeleteFile" value="false"/>
    <property name="MinimumAge" value="0"/>
    <property name="PhysicalDirectory" value="D:\mywork"/>
    <property name="Recursive" value="true"/>
    <property name="PollingFrequency" value="60"/>
    <property name="IncludeFiles" value="rj.*\.txt"/>
    <property name="UseHeaders" value="false"/>
    </activation-spec>
    </endpoint-activation>
    </adapter-config>
    Please help as why it is not getting picked up?
    Regards
    RJ

  • I tried to import a PDF of a line drawing into Photoshop Elements. The thumbnail looks fine, but when imported the file is empty. This used to work in the past. What is wrong and how do I solve this?

    I tried to import a PDF of a line drawing into Photoshop Elements. The thumbnail looks fine, but when imported the file is empty. This used to work in the past. What is wrong and how do I solve this?

    Hi
    The value of the Channel Strip volume etc is not stored within the C Strip setting, as you have discovered.
    If you really wanted, you could add a Gain plug to the strip, with it set to give the correct output level with the Fader set to 0
    (Or just set the fader manually in MS)
    CCT

  • How to Test, Inbound idoc ,with out the Sender System, using a Text File

    Hi Guru's .
    we wanted to test BLAORD03 inbound idoc (Message Type BLAORD).with out the SENDER SYSTEM.
    on the same client.
    we wanted to test this idoc with text file from our local machine.
    Can anyone give us detail steps.like how to create  File layout
    with Segment name,and values for the fields.how to pass this file to the system.
    Thanks in advance.

    Hi Aparna.
    My requirement is to test the idoc with Inbound File.
    Generate a file with the data entered through segments through we19 ,and use the same file for processing through we16.
    when i am trying to do this syst complaing about
    Partner Profile not available, and some times
    port not available. and some  times with
    'No further processing defined'.
    but i maintained part profiles and port perfectly.
    Can you help me in testing with test 'File' port.

  • How to test the RFC to Flat File scenario

    Hi,
    How to test the RFC to Flat File scenario
    regards,
    kiran

    Hi,
    After running the RFC it's going Dump.
    this is the error message i got.
    "Error analysis                                                                     
    An error occurred when executing a Remote Function Call.                     
    "CPI-C error CM_RESOURCE_FAILURE_NO_RETRY"                                                
    Status of connection.... "CODE=CM_RESOURCE_FAILURE_NO_RETRY -1 -1 SAPCODE=666
    CONV="                                                                      
    Internal error code.... "RFC_IO5"                                                           
    There is an error in the communication system. To clarify                    
    and resolve the error, contact your system administrator.                     "

  • How to test the simple .java file in cactus

    dear friends,
    i have use the junit first time .And i am working in weblogic8.1 so i have use cactus .But i face the problem to use it.
    1. how to test the simple .java file in cactus.
    2.how to run the cactus in weblogic 8.1.

    Hi,
    It is because the converter works on byte code and it only supports a subset of the Java language (see the JC specifications). It is kind of like compiling you code on Java 6 and trying to run it on Java 5. The JCDK outlines the required compiler version.
    Cheers,
    Shane

  • How to attach input file in the Test Script in SECATT in ECC6 ?

    Hi ,
    How to attach input file in the Test Script in ECC6  in Tcode SECATT ?
    For Testing in SECATT in ECC6, how to attach input file which contains multiple records ?
    Best Regards,
    Padhy

    Hi and Welcome to the Community!
    Since you have balance, and the issue is in your Work domain, you need to work with your server admins, as it's possible they are forbidding (via IT Policy) the ability to do as you desire.
    Good luck!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • How to test whether XI is sending file or not?

    Hi all!
    My scenario is like this:File(File sender Adapter)->XI->(HTTP receiver adapter)J2EE appl.
    I placed the xml file in D:\somedir on my PC. It is picking up the file, after picking it should post the same xml file to my j2ee appl. My servlet receives the xml file and display it on browser. But nothing is displayed. How to test whether XI is sending XML file to J2EE appl or not? All helpful answers are highly appreciated.
    Thanks!

    Hi
    In the file adapter i set processing mode as delete, it is picking up well from my d:\somedir.
    I got success flag in SXMB_MONI and successful status in RWB->message monitoring?
    Why my servlet is not able to display?
    All helpful answers are rewarded.
    public class DisplayRes extends HttpServlet {
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
                        doPost(request,response);
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         BufferedReader brin =new BufferedReader(new InputStreamReader(request.getInputStream()));
         String inputLine;
         StringBuffer sBuf = new StringBuffer();
         while ((inputLine = brin.readLine()) != null)
             sBuf.append(inputLine);
             brin.close();
             PrintWriter out = response.getWriter();
             response.setContentType("text/xml");
             //out.setContentType("text/xml");
             //out.println(sBuf.toString());
             out.write(sBuf.toString());
             out.flush();
    Thanks

  • How i can test my files in fp 9.0.0.115?

    hi ...
    how i change the version of my Flash player in adobe flash
    pro to test my files in FP 9.0.0.115?

    Libyano,
    > i already have the latest debug player but i do n't know
    where
    > i exchange the old debugger with the new one .
    The download page probably isn't as clear as it could be.
    According to
    a note on that page, "For users of Flash CS3 Professional, an
    update
    including all Debug and Release versions of this new Flash
    Player and a new
    Video Playback component supporting H.264 will be available
    via Adobe Update
    Manager in Flash CS3 shortly" (as of 12/3/07).
    In the mean time, drill down into the "players" folder in
    your Flash CS3
    installation folder. Inside "players," you'll find "debug"
    and "release."
    Rename the FlashPlayer.exe inside the debug folder (I renamed
    mine
    FlashPlayer_old.exe) and replace it with the debug player
    from Adobe.
    Rename the Adobe one to FlashPlayer.exe (or comparable Mac
    naming format, if
    you're on Mac). That did it for me. I could use Debug >
    Debug Movie and
    view H.264 content right in the Flash IDE. For some reason,
    replacing the
    release EXE didn't work for me -- but presumably that's where
    the "coming
    shortly" installer will come in handy.
    David Stiller
    Contributor, How to Cheat in Flash CS3
    http://tinyurl.com/2cp6na
    "Luck is the residue of good design."

Maybe you are looking for