parse csv format file into java arrays for generating ldif format file
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
add a comment |
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
2
Yes, you should be able to use the same array and keep assigning it toinput.split(",")
, whereinput
is your CSV string of user metadata. Add more code perhaps.
– Tim Biegeleisen
Nov 12 '18 at 5:14
add a comment |
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
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
java csv ldif
asked Nov 12 '18 at 5:13
Edward JungEdward Jung
32
32
2
Yes, you should be able to use the same array and keep assigning it toinput.split(",")
, whereinput
is your CSV string of user metadata. Add more code perhaps.
– Tim Biegeleisen
Nov 12 '18 at 5:14
add a comment |
2
Yes, you should be able to use the same array and keep assigning it toinput.split(",")
, whereinput
is your CSV string of user metadata. Add more code perhaps.
– Tim Biegeleisen
Nov 12 '18 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 '18 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 '18 at 5:14
add a comment |
1 Answer
1
active
oldest
votes
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();
Thanks for your kindness and brilliant idea, I'll try to make this java program works!
– Edward Jung
Nov 12 '18 at 7:31
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
Thanks for your kindness and brilliant idea, I'll try to make this java program works!
– Edward Jung
Nov 12 '18 at 7:31
add a comment |
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();
Thanks for your kindness and brilliant idea, I'll try to make this java program works!
– Edward Jung
Nov 12 '18 at 7:31
add a comment |
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();
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();
answered Nov 12 '18 at 5:33
Dark KnightDark Knight
6,31442749
6,31442749
Thanks for your kindness and brilliant idea, I'll try to make this java program works!
– Edward Jung
Nov 12 '18 at 7:31
add a comment |
Thanks for your kindness and brilliant idea, I'll try to make this java program works!
– Edward Jung
Nov 12 '18 at 7:31
Thanks for your kindness and brilliant idea, I'll try to make this java program works!
– Edward Jung
Nov 12 '18 at 7:31
Thanks for your kindness and brilliant idea, I'll try to make this java program works!
– Edward Jung
Nov 12 '18 at 7:31
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
Yes, you should be able to use the same array and keep assigning it to
input.split(",")
, whereinput
is your CSV string of user metadata. Add more code perhaps.– Tim Biegeleisen
Nov 12 '18 at 5:14