Hitachi Vantara Pentaho Community Forums
Results 1 to 6 of 6

Thread: Create a new file using Defined Java Class

  1. #1
    Join Date
    Mar 2016
    Posts
    19

    Default Create a new file using Defined Java Class

    Hi there

    I am new in Pentaho, moving from SSIS and I wonder why I can not create a new file from pentaho using the Define Java Class step. I have tested the next code and it works. But when I try to implement it from pentaho, even when there is not error message, the file is not created.

    Code:
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    
    
    public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
    {
        Object[] r = getRow();
    
    
        if(r==null)
        {
            setOutputDone();
            return false;
        }
    
    
        if(first)
        {
            first = false;
        }
        
         try{
               String contenido = "content";
            String Path = "C:\\Users\\Files\\Source\\test.txt";
            File f = new File(Path);
            
            if(!f.exists()){
                f.createNewFile();}
            
            FileWriter fw = new FileWriter(f.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            
            bw.write(contenido);
            bw.close();
                
            }catch(Exception e){
                    System.out.println("Error: "+e);
                    } 
        
    
    
        return true;
    
    
    }
    Thansk for any advice you can give me.

    Regards.
    Last edited by d2907; 03-10-2016 at 07:38 PM.

  2. #2
    Join Date
    Apr 2008
    Posts
    4,696

    Default

    Best advice I can give you is:
    Don't do it that way

    Use the steps provided to write files. They work. Really.

    SSIS and PDI do not work quite the same way. Take the time to learn how streaming data manipulation works.

  3. #3
    Join Date
    Mar 2016
    Posts
    19

    Default

    Hi


    The thing is. I am reading a csv file that needs to be changed. I am receiving this file with some errors from the source and I can not nothing regarding this, and I need to check line by line in the file. That is why I am trying to create a temporary file with the adjustments and work with him, leaving the original without any modification.
    Or if you could please, tell me what is the name of the step that can be use for this I would really appreciate it.

    Regards.

  4. #4
    Join Date
    Apr 2008
    Posts
    4,696

    Default

    Text File Input is used for reading files
    Text File Output is used to write files

    Without more information as to what you are trying to do, that's about as far as I can suggest.

  5. #5
    Join Date
    Mar 2016
    Posts
    19

    Default

    OK, let me try to explain.

    suppose the file has this configuration:
    id,name,address,observation (this is the header)
    "1,"a","street 1","new address"
    "2,"a","street 1","new "location" abroad"


    So, the file has as a text qualifier "", but this is also use in some of the values present inside some columns. That is why I need to adjust the file by creating a new one with other specifications: not text qualifier and new delimiter (|)


    id|name|address|observation (this is the header)
    1|a|street 1|new address
    2|a|street 1|new "location" abroad


    I can do this by reading line by line the old text and using the new. If I do not do this, the step is not going to read the file in the right way.

  6. #6
    Join Date
    Apr 2008
    Posts
    4,696

    Default

    You could use CSV Input to read the file
    You can use the Text File Output to write the file (using | as a delimiter)


    I'm still not seeing why you think User Defined Java Class is the way to do this.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.