exporting calculated fields JBuilder

Posted on 2011-10-31
Last Modified: 2012-05-12
HI: there may not be many JBuilder users out there but here goes:
I am importing a csv file into JBuilder and adding a calculated column.
I now want to re-export the file...but the calculated field does not pass.
Is there a workaround for this?
In Java terms I guess it is importing, amending and exporting vectors?

Question by:ClaytonGlass
    LVL 47

    Expert Comment

    >I am importing a csv file into JBuilder

    I'm not sure I understand - do you mean that you are reading CSV file
    by your java program which you run in JBuilder.

    Could you, please, you elaborate?

    Author Comment

    Of course.
    I have a csv file, output from a database. I need to add a column to the file. This column is calculated as being the last 2 digits of one of the other columns; so column50  needs to be 'the last 2 digits of column 4'.
    The file then needs to be passed forward for processing by some label printing software.

    I can - and am - doing this all within the (foxpro) database but would like to be able to adjust the file after export.   I have tried c++ and got hopelessly puzzled!  I have tried Java (NetBeans) and just as bad. C# has got me nowhere . VB I have not looked at. I have found a perl solution but not tried it.
    JBuilder  has got me further than anything else; I can read the file; I can add a calculated column. But when I try to output the file then the calculated column does not output!
    Trying to understand  the underlying process keeps leading me to vectors but in c++ at least I am never able to convert a 'data' type vector to string. Maybe Java/ Jbuilder has the same issue?
     As you see I don't mind how I solve the problem, just that I do!
    Thanks for your time.
    LVL 47

    Expert Comment


    Manipulations with csv file are not depndendt on NetBeans or JBuilder - they are perforemd by java program
    which can be executed either using one of these IDE or directly from the command line.
    Post a small snippet of your CSV file (just a few lines) and show how it needs to be changed - I'll try
    to help you with Java code to re-write the file. Then you can either use JBuilder or NetBeans or command line
    to execute this Java program.

    Author Comment

    Thank you very much! Please remember 2 things; I am a newbie; and I need to learn!
    I attach the file from the database. Please note that what  I want is already done. It is for my understanding that I want to recreate the process outside the database.
    The file has 2 lines. Note the end of the first line has the field "E:\Data\custpics\81.jpg" . This is calculated directly from the  the last 2 digits of fourth field, 781781.
    A final note; this I am doing at home, not here at work. I may not be able to look at any solutions until much later.
    Thanks again.

    LVL 47

    Expert Comment

    So you want to add the last column based on the last two digits of the fourth column?
    Original file would be the same without the last column - correct?

    Author Comment

    Yes, please!
    LVL 47

    Accepted Solution


    below id the Java program for re-writing file
    (cjheck the attached files - the BarCode-orig.txt file was the input,
    the BarCode-dest.txt file was the output of this program).

    Paste the contents of this code to the file

    Then,  I hope you have JDK (Java Development Kit) installed.
    If so, go to to Dos command line
    put this .java file and your input file (it should be called
    BarCode-orig.txt) into one folder
    go to that folder in the DOS window
    and type


    and after it compiles, say

    java RewriteCSVFile

    the new file called BarCode-dest.txt
    should appear in the same folder - check with
    the editor that it has an additional column you wanted.

    public class RewriteCSVFile {
        public static void main(String[] args) {
            try {
                BufferedReader br = new BufferedReader(new FileReader("BarCode_orig.txt"));
                PrintStream psout = new PrintStream(new FileOutputStream("BarCode_dest.txt"));
                String buff = null;
                while((buff=br.readLine()) != null){
                    String [] ss = buff.split(",");
                    psout.println(buff + ",\"E:\\Data\\custpics\\" + ss[3].substring(ss[3].length() - 2) + ".jpg\"");
            } catch(Exception ex){

    Open in new window


    Author Closing Comment

    Thank You Very Much!
    Excellent, helpful response.
    One question, if you don't mind. You chose Java. Is this because you use Java, because I asked for it, or because it was best for this? I am trying to learn when to use Java; when c#, when c++, when vb, etc.
    You are obviously an expert. You must find that  people don't ask 'do me a Java program'; they ask 'sort my problem.' I am keen to learn why you chose Java.
    Don't reply if you don't want to.
    Thanks again.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now