Help needed regarding file handling

I have a file path.txt which contains the path of 10 other files....I am attempting to send path.txt through command line arguement and then read each line at a time from the file. Now each line in the file is a path to another file. I have used a string to store each line and am calling a function func() where I am sending the string. Now using that string which contains the path of another file say 1.txt i am trying to open 1.txt .......I have given my prog below....sending path.txt is working fine but reading a path from path.txt and opening that particular file is not happening
if possible kindly correct my program or give any other prog to do this problem
import java.io.*;
class Prog {
     int size;
     static void func(String str1)               throws IOException
          int i;
          int cnt=-1;
          FileInputStream fin;
          try {
               fin = new FileInputStream(str1);
          catch(FileNotFoundException exc)
               System.out.println(exc);
               return;
          catch(ArrayIndexOutOfBoundsException exc)
               System.out.println("Usage: Showfile file");
               return;
          do{
               i=fin.read();
               cnt++;
          }while(i!=-1);
          System.out.println("File size="+cnt);
          fin.close();
     public static void main(String args[]) throws IOException
          int i;
          int cnt=-1;
          String str1="",str="";
          FileInputStream fin;
          for(i=0;i<args.length;i++)
               str+=args;
               str+=" ";
          str=str.substring(0,str.length()-1);
          try {
               fin = new FileInputStream(str);
          catch(FileNotFoundException exc)
               System.out.println("File not found");
               return;
          catch(ArrayIndexOutOfBoundsException exc)
               System.out.println("Usage: Showfile file");
               return;
          i=0;
          while(true){
               i=fin.read();
               if(i==-1)
                    break;
               cnt++;
               if((char) i!='\n')
                         str1=str1+(char)i;
               else
                    func(str1);
                    str1="";
          System.out.println("File size="+cnt);
          fin.close();

just putting it in code blocks
import java.io.*;
class Prog {
int size;
static void func(String str1) throws IOException
int i;
int cnt=-1;
FileInputStream fin;
try {
fin = new FileInputStream(str1);
catch(FileNotFoundException exc)
System.out.println(exc);
return;
catch(ArrayIndexOutOfBoundsException exc)
System.out.println("Usage: Showfile file");
return;
do{
i=fin.read();
cnt++;
}while(i!=-1);
System.out.println("File size="+cnt);
fin.close();
public static void main(String args[]) throws IOException
int i;
int cnt=-1;
String str1="",str="";
FileInputStream fin;
for(i=0;i<args.length;i++)
str+=args;
str+=" ";
str=str.substring(0,str.length()-1);
try {
fin = new FileInputStream(str);
catch(FileNotFoundException exc)
System.out.println("File not found");
return;
catch(ArrayIndexOutOfBoundsException exc)
System.out.println("Usage: Showfile file");
return;
i=0;
while(true){
i=fin.read();
if(i==-1)
break;
cnt++;
if((char) i!='\n')
str1=str1+(char)i;
else
func(str1);
str1="";
System.out.println("File size="+cnt);
fin.close();
}

Similar Messages

  • Some help needed regarding Files and URLs on a server

    I don't get it - my applet works in a local directory, but not on a server. This has to do with the loading of files (I load an array of images to use, but when I attempt to use that array, it comes up with the error ArrayIndexOutOfBounds), but I can't understand what the problem is...
    I have a code that loads files (using File objects) from the current directory (a .jar file) into the program. I do not simply type in the file names - I set it so that the program searches for them based on a prefix in the file name. This works fine on my computer, and I never navigate to files outside of the .jar file. Why might this have a problem on a server? Would URL objects be more appropriate?
    Note: I alter the file base String in this way before loading it (this stands for the current directory)
    fileBase = applet.codeBase.toString().replace('\\', '/');codeBase is simply the applet's codeBase() method put into a URL variable. The replace statement is there so that there are no backslashes. And this works perfectly on my computer. Any help? Would it work if I used a URL instead? If so, how do I perform a search function with a URL (so that all the filenames within a certain directory are returned as Strings)?

    Thanks for the info, it helps a lot. You say there is no "practical" way to search for a file under a URL path. What I am trying to do is load a file that begins with a particular prefix. (eg. I wish to load a file called "funnyImage0011204924." However, the numbers after the prefix "funnyImage" are variable, and might require change in the future. Is it possible to load any file with the prefix "funnyImage," using URL methods? Would I need to create a new class? Is this impossible?)
    Please remember that I do not plan to go outside the .jar file, so there is no point in trying to get around server permissions and all that if it is unnecessary.

  • Help needed regarding the updation of "Relationships" in BP

    Hello Guys,
    This is to request you to kindly help me regarding the following.
    We have a scenario where all the employees assigned to an Organizational unit (in PPOMA_CRM) are not showing in the "Relationships" ("Has Employee")in the BP transaction of that Organizational Unit.
    Could anyone let me know whether there is any update program that updates the "Relationships" from the Organizational asssignment. Or we need to enter the employees manually in BP "Relationships". Please help. Thanks in anticipation.
    Regards,
    Kishore.

    Hi Amit,
    Thanks alot for your reply. Its really helpful for me.
    So,we usually enter these relationships manually only, right? Before going ahead with the custom program, could you please let me know whether there is any SAP note related to this.Once again thanks alot for you help.
    Regards,
    Kishore.

  • M new to this forum + new to java please help me with file handling program

    hi i want to make a file handling program where in i want to input a text file say f1 whose style is mentioned as below
    aaa...bcd
    aaabbc
    acdce
    a..dd
    abbcd
    now i want to write d out put of file f1 to file f2 but only those string entries widout any ... in them how to do that :-(( please help :((

    import java.io.*;
    import java.lang.*;
    class javcsse{
             void javsce (){
              BufferedReader in;
            PrintWriter out;
            String line;
            try
                in = new BufferedReader(new FileReader("e:\\cntcs\\n7.txt"));
                out = new PrintWriter("e:\\cntcs\\n8.txt");
               line = in.readLine();
               while(line != null)
                     if(line.contains("...") && line.contains("....")){
                         break ;                
                         else{
                               if(line.contains("cc"))
                              System.out.println(line+"\n");
                                      out.println(line);
                    line = in.readLine();
                in.close();
                out.close();
            } catch (Exception ex)
                System.err.println(ex.getMessage());
      public class javcse{
        public static void main(String[] args) {
            new javcsse();
    }hey i wrote this code yet could u tell y is it still not working :((

  • Help needed regarding Segment Qualifiers

    Hi,
    In my process of implementing Apps R12 afresh, we just created the segments and assigned them their flexfield qualifiers today. In that, the one assigned towards alancing segment shows the value qualifiers like that of natural accounting segment, unlike the bal. segment value qualifier.
    I mean, when we try to insert a a value in the bal.segment it asks for qualifiers such as nature:expense/revenue/liability/asset, instead of going for the allow posting and allow budgeting alone. This is crazy, and I need your support.
    Thanks,
    Mukunthan L

    Hi Amit,
    Thanks alot for your reply. Its really helpful for me.
    So,we usually enter these relationships manually only, right? Before going ahead with the custom program, could you please let me know whether there is any SAP note related to this.Once again thanks alot for you help.
    Regards,
    Kishore.

  • Help needed Regarding Project Server - 2013 Workflow

    Hi All,
    I am new to Project server 2013 Workflow, hence please help me regarding this. Pardon me if this question is too trivial. 
    I have created a project type associated with a workflow and my workflow is as follows :
    So I am not doing anything here, I am just testing the workflow as mentioned by technet site : http://technet.microsoft.com/en-us/library/dn458865(v=office.15).aspx
    But it is mentioned that, after a minute or 2, the workflow state will change, also they have mentioned to press the Submit button.
    But in my case, the workflow is not moving to next stage [It just says 'The workflow is still processing - which never changes after hours] or I am getting the submit button (Submit button is disabled on the ribbon). Below is the state of my workflow :
    PS : I have made the user added to Portfolio managers group as well. But still I am having this same issue. 
    The Workflow manager is installed properly, and it is working fine in case of List workflow. I am facing the issue only wrt Site workflow for Project server 2013.
    Please help me to solve this issue.
    Thanks,
    shanky

    Hi Kiran,
    I am now facing issue while assigning a task to a person in the workflow.
    I am having a person named say 'John' , who is included in Project Manager as well as Portfolio Manager.
    And I am using a workflow as :
    Stage : Conceptual
    Assign a task to John (Task outcome to Variable: Outcome5 | Task ID to Variable: TaskID3 )
    Transition to stage
    Go to Approval
    But this is again giving issue as :
    Workflow Internal status : Cancelled
    Details: System.ApplicationException: HTTP 401 {"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have
    permission to perform this action or access this resource."}}}
    PS : I have used the same Sharepoint admin account for 'Account Name' in ‘User Profile Sync' , Is this causing the issue? Please let me know.
    Thanks,
    Shanky

  • Help needed regarding BADI.

    hi all,
    can anyone plz tell me how to define BADI and how create an interface.
    plz tell from everything regarding that, i have work with basic ABAP only.
    anykind of links and any kind of matter will be helpful and you will be rewarded with points for your help difinatly.
    regards.
    raman.

    Hi Raman,
    Please search the forum and you have lots and lots of links in it. For you to start with, try these links,
    The specified item was not found.
    BADI
    Best Regards.

  • Help needed regarding font sizes

    Iam generating pdf documents using oracle developer's report builder.
    When i generate and view those pdf's using the web previewer thay appear to be quite fine,whereas when i host them on ias the font sizes gets bigger, thus lot of text gets truncated.
    Is there any parameters that has to be set for it.Pls help

    Hi Amit,
    Thanks alot for your reply. Its really helpful for me.
    So,we usually enter these relationships manually only, right? Before going ahead with the custom program, could you please let me know whether there is any SAP note related to this.Once again thanks alot for you help.
    Regards,
    Kishore.

  • Help needed regarding BPM

    Hi frnds,
    I am having 5 different file structures inbound.. i want to group the files of each structure.
    Please suggest the initial strcture of how the block should look like..I need the files of sametype to be placed in one container,like that i need the procedure for all 5 different structures..
    How to proceed with this
    TIA,
    Mahesh

    Hi,
    In the block step, you will need to use fork with 5 branches. For every branch, there will be one receive step which will start the process.
    -Supriya.

  • Help needed regarding replication in ds5.2sp4

    Hi ,
    I am new to ldap . I am able to establish replication between master and consumer and trying to update it is getting update but i am geting the following error
    in error log
    INFORMATION - NSMMReplicationPlugin - conn=-1 op=-1 msgId=-1 - Replication bind to consumer alpha.ad.com:19941 failed:
    [16/May/2007:13:48:26 -0700] - INFORMATION - NSMMReplicationPlugin - conn=-1 op=-1 msgId=-1 - Failed to connect to replication consumer alpha.ad.com:19941
    [16/May/2007:13:48:26 -0700] - ERROR<8318> - Repl. Transport - conn=-1 op=-1 msgId=-1 - [S] Bind failed with response: Failed to bind to remote (900).
    Please help me regarding this .
    Message was edited by:
    ap7926

    If data is getting replicated from master to consumer then the bind for that specific replication agreement is working.
    Check your timestamps and current log entries. Are the "Failed to connect to replication" messages currently being generated? As long as your replication agreement is enabled the supplier will try to keep things up and running, retrying a failed consumer regularly (and generating about 1 set of log messaages per minute on my systems). So you'll get those messages on the supplier when a good consumer is down (the nsslapd directory server process that is).
    If you don't have these messages being generated currently then this probably means that your consumer was down around "16/May/2007:13:48:26 -0700" but is ok now. In that case those messages aren't of big concern. They're just telling you that you had a problem, which you hopefully already knew about.
    If replication is working (test by making a change on the supplier and checking it on the consumer) AND you're still concurrently getting these messages regularly then you have something interesting going on, probably due to a configuration issue. Without seeing the details it's difficult say what it would be.

  • Help needed regarding AE SDK compiled/linked out file extension

    Hi,
       I am new to the AE SDK plug-in build, and to the Forum.
       How to select .aex file format extension for the compiler and linker single file output?
       My system is:
             Adobe CS 5
             Windows 7 with 64-bit processing
             Visual Studio 2008 SP1
       I am stuck and need help.

    I got a direct answer - it is the concept of linking to a library (.dll) and not to an executable (.exe).
    This is encouraging, thank you. 

  • Help needed regarding reading in a text file and tokenizing strings.

    Hello, I require help with a task I've been set, which asks me to read in a text file, and check the contents for errors. The text file contains lines as follows.
    surname:forename:1234:01-02-06
    I can read in the file, but dont know how to split the strings so each token can be tested (ie numbers in the name tokens)
    However, I am not allowed to use regex functions, only those found in java.io.*
    I think i should be putting the tokens into an array, but have had no luck so far in doing so. Any help would be appreciated.

    public class Validator {
         public static void main(String args[]) {
              String string = "Suname:Forename:1234:01_02-06";
              String stringArray[] = string.split(":");
              System.out.println (validateLetters(stringArray[0]));//returns true
              System.out.println (validateNumbers(stringArray[3]));//returns false
         static boolean validateLetters(String s) {
                 for(int i = 0; i < s.length(); i++) {
                 char c = s.charAt(i);
                 if ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z')) {
                         return false; //return false if one of characters is other than a-z A-Z
                 }//end if
                 }//end for
                 return true;
         }//end validateLetters
         static boolean validateNumbers(String s) {
                 for(int i = 0; i < s.length(); i++) {
                 char c = s.charAt(i);
                 if ((c < '0' || c > '9') && (c != '-')) {
                         return false; //return false if one of characters is other than 0-9 or -
                 }//end if
                 }//end for
                 return true;
         }//end validateNumbers
    }

  • Help needed for file processing using FTP

    Hi All,
    I am new to ODI tool and currently we are implementing one project in ODI. Could you please, any one help me on the following requirement... how to implement it?
    Scenario:
    i) I need to pick a file from remote host 'outbox' dir using FTP process, and place into local 'temp' dir. (I can do it with odiFTPGet tool)
    ii) Change the file as per target business requirement.??? ( this step challenging me)
    for ex:
    if source file name : <project name>_<source ID>_<transaction name>_<unique id>.txt
    target name should be : 1234_<transaction name>_<sysdate in yyyyMMddhhmmss>_<unique id>_2345.txt ( here 1234 and 2345 are hard coded values)
    iii) Later move to local 'temp' to local 'outbox' dir. ( I can do it with odiFileMove tool)
    iv) After successful process move the file from remote 'outbox' to remote 'archive' dir ??? (again this is challenging me).
    For this my questions are:
    1) How to get file name into a variable ( In one of the post , it says we need to create data model and data stores, and interface to get the file names into a file. apart from is there any easy way i can implement it in package it self?)
    2) How to tokenize a long string ( i.e., need to tokenize the source file to get <unique id> and <transaction name> and map to target file name)
    3) How to define implementation for Java in user function?? do we need to use class declarations and import statements?? I need a sample user function in Java.
    4) How to move/rename a file in remote server?? ( need to move file from remote 'outbox' server to remote archive' dir)
    5) If any step in package fails, How to get the error msg into a variable which i can use for sending mail and raise a ticket in remedy?? ( I will pass that variable to as content to mail and remedy ticket)
    6) How to handle list type data (string list) by variables in ODI?? (As we can define single variable not as list.)
    I am sorry to ask all my queries I a single post. But I need to solutions for all to implement this in my project.
    Thanks in advance. Appreciate early response.
    Regards,
    Kiran.N

    Can any one share your thoughts for my request.
    Thanks in advance.
    Regards,
    Kiran

  • Help needed for file to file communication

    Dear all I am working on file to file adapter in XI 3.0 . I tried to different waysof flat file location C:\ and C:/ I am not soure witch one is currect and any time i am getting NO MESSAGE FOUND ! error in SX_MONI.
    and
    Any one have step by step clear procedure for File to File Adapter SAP XI 3.0.
    Thanking U,
    <b>Murali</b>.

    Hi Murali,
    first we need to uderstand how to do content conversion ( to convert flat files to xml format ) for which u can go through the following links :
    /people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
    /people/jeyakumar.muthu2/blog/2005/11/29/file-content-conversion-for-unequal-number-of-columns
    /people/anish.abraham2/blog/2005/06/08/content-conversion-patternrandom-content-in-input-file
    http://help.sap.com/saphelp_nw04/helpdata/en/89/90fd3f0521c842e10000000a1550b0/frameset.htm
    then file to file scenarios:
    /people/venkat.donela/blog/2005/03/02/introduction-to-simplefile-xi-filescenario-and-complete-walk-through-for-starterspart1
    /people/venkat.donela/blog/2005/03/03/introduction-to-simple-file-xi-filescenario-and-complete-walk-through-for-starterspart2
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    http://help.sap.com/saphelp_nw04/helpdata/en/43/25112ab6140b25e10000000a1553f6/frameset.htm
    Configuring sender file adapter:
    /people/sravya.talanki2/blog/2005/08/16/configuring-generic-sender-file-cc-adapter
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    Configuring receiver file adapter:
    /people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
    /people/jayakrishnan.nair/blog/2005/06/20/dynamic-file-name-using-xi-30-sp12-part--i
    going through all the given links you will not have any problems doing a file to file scenario with any constraints.
    Regards,
    abhy

  • Help needed Regarding a business logic

    Hi all,
    My business requirement is
    requires to get a checksum from the KIOSK field. This would be something like a rule that for a given KIOSK generates a number from 0 to 9.
    The Field value contains alphanumerical
    Can any of guys help me in this logic.how to generate a checksum for a given field..
    Thanks & Regards;
    Vinit

    Alright I found something  I am not  sure if it is of use to you , A checksum is generally used to  detect the integrity of file
    it is calculated oin basis of hash algorithms so  how it is useful to for incoming filed values i m not  sure
    Please find the links below
    http://en.wikipedia.org/wiki/Checksum
    http://www.fastsum.com/support/online-help/checksums.php
    http://www.flounder.com/checksum.htm
    http://www.mkyong.com/java/how-to-generate-a-file-checksum-value-in-java/
    If it is useful , you need to implement a hash algorithm
    regards
    Ninad

Maybe you are looking for

  • Unable to open documents in Office (Word and Excel) - 3 authentication prompts followed by 'Could not open ...'

    I am getting multiple authentication prompts when I try to open or create a new .docx or .xslx document from SharePoint 2010.  I tried this on different machines and on different browsers (IE and Firefox) and see the same behavior. I am the site coll

  • Call exe from an exe

    hello How we can call an exe from an another exe. If the exe installed in a PC, it had not LabView and whatever files or drivers needed. I create a dll file. call functions node used to call the dll. But it is not calling the dll please give a soluti

  • Play multiple album art in ipod G5

    I can see multiple album art for a single song in itune by clicking on the right arrow above the image, but when I transfer the songs to ipod I can only see one of the images. and that is a reduced sized image, even if I double click the center butto

  • How to implement sorting on a group of records by clicking on the header?

    I am using Oracle Forms 6i. Now I have a table of records having a column header in a custom form. Now I want to sort that column data by clicking on the column header (showing an arrow mark of asc/desc while I press the button). How to implement thi

  • IWeb Rotates jpeg on upload

    Ok, this is very weird. I'm using iWeb 3.0.4; on MAC OS 10.7.5, on a MacBook Pro 15-inch early 2008. I've been working on the web site in question for about 5 years and this has never happened before. I do modifications, updates and ftps all the time