parse csv format file into java arrays for generating ldif format file










0














I am a rookie in java coding area,
I am trying to parse a csv format file, split with only commas(,)
this file includes users' account names and true names,
for example, it looks like: tom123,Tom Halland,kelly02,Kelly Chen,..and so on,
I want to parse these user's data into something like arrays using java,
so I can reuse this array, then to generate ldif format file and import it into LDAP server to create accounts automatically,
is there any easier way to do it? or any technical advises for me?
Thanks a lot!










share|improve this question

















  • 2




    Yes, you should be able to use the same array and keep assigning it to input.split(","), where input is your CSV string of user metadata. Add more code perhaps.
    – Tim Biegeleisen
    Nov 12 at 5:14















0














I am a rookie in java coding area,
I am trying to parse a csv format file, split with only commas(,)
this file includes users' account names and true names,
for example, it looks like: tom123,Tom Halland,kelly02,Kelly Chen,..and so on,
I want to parse these user's data into something like arrays using java,
so I can reuse this array, then to generate ldif format file and import it into LDAP server to create accounts automatically,
is there any easier way to do it? or any technical advises for me?
Thanks a lot!










share|improve this question

















  • 2




    Yes, you should be able to use the same array and keep assigning it to input.split(","), where input is your CSV string of user metadata. Add more code perhaps.
    – Tim Biegeleisen
    Nov 12 at 5:14













0












0








0







I am a rookie in java coding area,
I am trying to parse a csv format file, split with only commas(,)
this file includes users' account names and true names,
for example, it looks like: tom123,Tom Halland,kelly02,Kelly Chen,..and so on,
I want to parse these user's data into something like arrays using java,
so I can reuse this array, then to generate ldif format file and import it into LDAP server to create accounts automatically,
is there any easier way to do it? or any technical advises for me?
Thanks a lot!










share|improve this question













I am a rookie in java coding area,
I am trying to parse a csv format file, split with only commas(,)
this file includes users' account names and true names,
for example, it looks like: tom123,Tom Halland,kelly02,Kelly Chen,..and so on,
I want to parse these user's data into something like arrays using java,
so I can reuse this array, then to generate ldif format file and import it into LDAP server to create accounts automatically,
is there any easier way to do it? or any technical advises for me?
Thanks a lot!







java csv ldif






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 5:13









Edward Jung

31




31







  • 2




    Yes, you should be able to use the same array and keep assigning it to input.split(","), where input is your CSV string of user metadata. Add more code perhaps.
    – Tim Biegeleisen
    Nov 12 at 5:14












  • 2




    Yes, you should be able to use the same array and keep assigning it to input.split(","), where input is your CSV string of user metadata. Add more code perhaps.
    – Tim Biegeleisen
    Nov 12 at 5:14







2




2




Yes, you should be able to use the same array and keep assigning it to input.split(","), where input is your CSV string of user metadata. Add more code perhaps.
– Tim Biegeleisen
Nov 12 at 5:14




Yes, you should be able to use the same array and keep assigning it to input.split(","), where input is your CSV string of user metadata. Add more code perhaps.
– Tim Biegeleisen
Nov 12 at 5:14












1 Answer
1






active

oldest

votes


















0














I am sharing code snippet from one of my previous assignments. Basically code does following tasks:



1) Read CSV file line by line



2) Split each line into token with help of predefined characher(in case of csv it's ',')



3) Generate a string form of record in desired ldif format



4) write record to output file



String inputCSVFile = "/input_folder_path/sample.csv"; 
BufferedReader bufferedReader = null;
String lines = "";
String splitChar = ",";
String columns;

int count = 0;

try

PrintStream printStream = new PrintStream(new FileOutputStream("/output_folder_path/e.ldif"));// Step 1
bufferedReader = new BufferedReader(new FileReader(inputCSVFile));

while ((lines = bufferedReader.readLine()) != null)


columns = lines.split(splitChar);// Step 2


if (count > 0) // Step 3 ,4
printStream.println("dn: cn="+columns[1]+", ou="+columns[2]+", o=Data"
+ "ngivenName: "+columns[0]
+ "nsn: "+columns[3]
+ "n"
);

count++;



catch (Exception e)
e.printStackTrace();
finally
if (bufferedReader != null)
try
bufferedReader.close();
catch (IOException e)
e.printStackTrace();








share|improve this answer




















  • Thanks for your kindness and brilliant idea, I'll try to make this java program works!
    – Edward Jung
    Nov 12 at 7:31










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256261%2fparse-csv-format-file-into-java-arrays-for-generating-ldif-format-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I am sharing code snippet from one of my previous assignments. Basically code does following tasks:



1) Read CSV file line by line



2) Split each line into token with help of predefined characher(in case of csv it's ',')



3) Generate a string form of record in desired ldif format



4) write record to output file



String inputCSVFile = "/input_folder_path/sample.csv"; 
BufferedReader bufferedReader = null;
String lines = "";
String splitChar = ",";
String columns;

int count = 0;

try

PrintStream printStream = new PrintStream(new FileOutputStream("/output_folder_path/e.ldif"));// Step 1
bufferedReader = new BufferedReader(new FileReader(inputCSVFile));

while ((lines = bufferedReader.readLine()) != null)


columns = lines.split(splitChar);// Step 2


if (count > 0) // Step 3 ,4
printStream.println("dn: cn="+columns[1]+", ou="+columns[2]+", o=Data"
+ "ngivenName: "+columns[0]
+ "nsn: "+columns[3]
+ "n"
);

count++;



catch (Exception e)
e.printStackTrace();
finally
if (bufferedReader != null)
try
bufferedReader.close();
catch (IOException e)
e.printStackTrace();








share|improve this answer




















  • Thanks for your kindness and brilliant idea, I'll try to make this java program works!
    – Edward Jung
    Nov 12 at 7:31















0














I am sharing code snippet from one of my previous assignments. Basically code does following tasks:



1) Read CSV file line by line



2) Split each line into token with help of predefined characher(in case of csv it's ',')



3) Generate a string form of record in desired ldif format



4) write record to output file



String inputCSVFile = "/input_folder_path/sample.csv"; 
BufferedReader bufferedReader = null;
String lines = "";
String splitChar = ",";
String columns;

int count = 0;

try

PrintStream printStream = new PrintStream(new FileOutputStream("/output_folder_path/e.ldif"));// Step 1
bufferedReader = new BufferedReader(new FileReader(inputCSVFile));

while ((lines = bufferedReader.readLine()) != null)


columns = lines.split(splitChar);// Step 2


if (count > 0) // Step 3 ,4
printStream.println("dn: cn="+columns[1]+", ou="+columns[2]+", o=Data"
+ "ngivenName: "+columns[0]
+ "nsn: "+columns[3]
+ "n"
);

count++;



catch (Exception e)
e.printStackTrace();
finally
if (bufferedReader != null)
try
bufferedReader.close();
catch (IOException e)
e.printStackTrace();








share|improve this answer




















  • Thanks for your kindness and brilliant idea, I'll try to make this java program works!
    – Edward Jung
    Nov 12 at 7:31













0












0








0






I am sharing code snippet from one of my previous assignments. Basically code does following tasks:



1) Read CSV file line by line



2) Split each line into token with help of predefined characher(in case of csv it's ',')



3) Generate a string form of record in desired ldif format



4) write record to output file



String inputCSVFile = "/input_folder_path/sample.csv"; 
BufferedReader bufferedReader = null;
String lines = "";
String splitChar = ",";
String columns;

int count = 0;

try

PrintStream printStream = new PrintStream(new FileOutputStream("/output_folder_path/e.ldif"));// Step 1
bufferedReader = new BufferedReader(new FileReader(inputCSVFile));

while ((lines = bufferedReader.readLine()) != null)


columns = lines.split(splitChar);// Step 2


if (count > 0) // Step 3 ,4
printStream.println("dn: cn="+columns[1]+", ou="+columns[2]+", o=Data"
+ "ngivenName: "+columns[0]
+ "nsn: "+columns[3]
+ "n"
);

count++;



catch (Exception e)
e.printStackTrace();
finally
if (bufferedReader != null)
try
bufferedReader.close();
catch (IOException e)
e.printStackTrace();








share|improve this answer












I am sharing code snippet from one of my previous assignments. Basically code does following tasks:



1) Read CSV file line by line



2) Split each line into token with help of predefined characher(in case of csv it's ',')



3) Generate a string form of record in desired ldif format



4) write record to output file



String inputCSVFile = "/input_folder_path/sample.csv"; 
BufferedReader bufferedReader = null;
String lines = "";
String splitChar = ",";
String columns;

int count = 0;

try

PrintStream printStream = new PrintStream(new FileOutputStream("/output_folder_path/e.ldif"));// Step 1
bufferedReader = new BufferedReader(new FileReader(inputCSVFile));

while ((lines = bufferedReader.readLine()) != null)


columns = lines.split(splitChar);// Step 2


if (count > 0) // Step 3 ,4
printStream.println("dn: cn="+columns[1]+", ou="+columns[2]+", o=Data"
+ "ngivenName: "+columns[0]
+ "nsn: "+columns[3]
+ "n"
);

count++;



catch (Exception e)
e.printStackTrace();
finally
if (bufferedReader != null)
try
bufferedReader.close();
catch (IOException e)
e.printStackTrace();









share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 5:33









Dark Knight

6,01642748




6,01642748











  • Thanks for your kindness and brilliant idea, I'll try to make this java program works!
    – Edward Jung
    Nov 12 at 7:31
















  • Thanks for your kindness and brilliant idea, I'll try to make this java program works!
    – Edward Jung
    Nov 12 at 7:31















Thanks for your kindness and brilliant idea, I'll try to make this java program works!
– Edward Jung
Nov 12 at 7:31




Thanks for your kindness and brilliant idea, I'll try to make this java program works!
– Edward Jung
Nov 12 at 7:31

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256261%2fparse-csv-format-file-into-java-arrays-for-generating-ldif-format-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands