Parsing & reading/writing to a Custom fileHow do I parse a YAML file?How do I read / convert an InputStream into a String in Java?How do I create a Java string from the contents of a file?How to parse JSON in JavaSort ArrayList of custom Objects by propertyHow do I create a file and write to it in Java?How to avoid Java code in JSP files?Reading a plain text file in JavaHow to read a large text file line by line using Java?Read a single file with multiple BufferedReadersCan you help me to read this YAML file?
Losing queen and then winning the game
Is there reliable evidence that depleted uranium from the 1999 NATO bombing is causing cancer in Serbia?
How did installing this RPM create a file?
What game is this character in the Pixels movie from?
Find first and last non-zero column in each row of a pandas dataframe
How to describe POV characters?
Was it really unprofessional of me to leave without asking for a raise first?
Buliding a larger matrix from a smaller one
Graph problems as integer programs
Is there a canon reason why Klingon and Romulan vessels are so similar in shape?
How to securely dispose of a smartphone?
Put my student loan in parents’ second mortgage - help?
What's the rule for a natural 20 on a Perception check?
Different budgets within roommate group
Balanced parentheses using STL C++
Why won't the ground take my seed?
Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?
Who are these Discworld wizards from this picture?
I hit a pipe with a mower and now it won't turn
How is this practical and very old scene shot?
How can I write a panicked scene without it feeling like it was written in haste?
In native German words, is Q always followed by U, as in English?
How hard is it to sell a home which is currently mortgaged?
Integral from infinity to infinity
Parsing & reading/writing to a Custom file
How do I parse a YAML file?How do I read / convert an InputStream into a String in Java?How do I create a Java string from the contents of a file?How to parse JSON in JavaSort ArrayList of custom Objects by propertyHow do I create a file and write to it in Java?How to avoid Java code in JSP files?Reading a plain text file in JavaHow to read a large text file line by line using Java?Read a single file with multiple BufferedReadersCan you help me to read this YAML file?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am working on creating my own Custom file parser (it can read & write a .yml file or any other custom text file)
Right now I am just working on reading a pre-written file.
(Yes i have looked at several other similar issues. these didn't seem to even get close to what i'm looking for as i don't want to use an external library.
[a link] (How do I parse a YAML file?) )
However, the code I have currently does not seem to be returning the correct results.
It keeps returning an empty string, implying that the file didn't contain the values i asked for.
protected String readValue(String value)
BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource("Locale.txt")));
boolean isMultiline = false;
String multiLineCombo = "";
for (String s : reader.lines().toArray(String[]::new))
if (s.startsWith(Pattern.compile("[^a-zA-Z0-9]") + ""))
continue;
if (s.trim().startsWith(Pattern.quote("(?i)") + value + ":")) -"))
isMultiline = true;
continue;
if (isMultiline)
if (!s.contains(":"))
multiLineCombo = multiLineCombo.concat(s + "n");
continue;
else
isMultiline = false;
return multiLineCombo;
try
reader.close();
catch (Exception e)
return s.substring(s.indexOf(":"));
return "";
I'm looking for it to read simple values constructed like so:
# comments...
OwnerName: 'something here'
# more comments
# .
# yeet...
ListOfNames:
- Ann
- Brent
- Crumpled Bananas
- more values
# multiline strings like this
MultipleLines: |-
Line one
Line two
and line three
Yes, I have written the values i'm trying to pull in the target file, the values are in there, i'm just reading them wrongly.
If anybody has some tips or can help me as to what i'm doing wrong here, that would be awesome!
Edit:
Seems i need to explain why i'm attempting to create my own file reader instead of using a third-party such as SnakeYaml... Mainly because i do not want to specifically parse only YAML files, I'm looking for this as more of my own custom data storage system. The library i'm working with has a built-in yaml reader/writer, but it ignores comments, deleting them and removing any white spaces and formatting i add in. Additionally, I do not want this to be overly dependent on whether said java application has the specified libraries available. (depending on whether it has access to the Internet or not to download resources)
As such, i want to create my own, both to negate having to depend on external libraries and to increase reliability and customize-ability.
java
|
show 1 more comment
I am working on creating my own Custom file parser (it can read & write a .yml file or any other custom text file)
Right now I am just working on reading a pre-written file.
(Yes i have looked at several other similar issues. these didn't seem to even get close to what i'm looking for as i don't want to use an external library.
[a link] (How do I parse a YAML file?) )
However, the code I have currently does not seem to be returning the correct results.
It keeps returning an empty string, implying that the file didn't contain the values i asked for.
protected String readValue(String value)
BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource("Locale.txt")));
boolean isMultiline = false;
String multiLineCombo = "";
for (String s : reader.lines().toArray(String[]::new))
if (s.startsWith(Pattern.compile("[^a-zA-Z0-9]") + ""))
continue;
if (s.trim().startsWith(Pattern.quote("(?i)") + value + ":")) -"))
isMultiline = true;
continue;
if (isMultiline)
if (!s.contains(":"))
multiLineCombo = multiLineCombo.concat(s + "n");
continue;
else
isMultiline = false;
return multiLineCombo;
try
reader.close();
catch (Exception e)
return s.substring(s.indexOf(":"));
return "";
I'm looking for it to read simple values constructed like so:
# comments...
OwnerName: 'something here'
# more comments
# .
# yeet...
ListOfNames:
- Ann
- Brent
- Crumpled Bananas
- more values
# multiline strings like this
MultipleLines: |-
Line one
Line two
and line three
Yes, I have written the values i'm trying to pull in the target file, the values are in there, i'm just reading them wrongly.
If anybody has some tips or can help me as to what i'm doing wrong here, that would be awesome!
Edit:
Seems i need to explain why i'm attempting to create my own file reader instead of using a third-party such as SnakeYaml... Mainly because i do not want to specifically parse only YAML files, I'm looking for this as more of my own custom data storage system. The library i'm working with has a built-in yaml reader/writer, but it ignores comments, deleting them and removing any white spaces and formatting i add in. Additionally, I do not want this to be overly dependent on whether said java application has the specified libraries available. (depending on whether it has access to the Internet or not to download resources)
As such, i want to create my own, both to negate having to depend on external libraries and to increase reliability and customize-ability.
java
Have you tried debugging your code? Learning how to use a debugger is probably the best thing for you to do right now.
– Tim Biegeleisen
Mar 25 at 13:19
Completely forgot about that, I will start there.
– FlailoftheLord -
Mar 25 at 13:24
At your level of experience you should definitely use a ready-made YAML parser instead of rolling your own. The YAML specification is over 70 pages long and full of horrible details and edge cases. You won't get anything right by doing it yourself. Therefore it is essential that you explain in your question why you don't want to use a third-party YAML parser.
– Roland Illig
Mar 25 at 13:53
To clarify, i was looking more into reading any filetype formatted as a .yml file, this could be a text file, .java file, anything with the correct encoding and format which i am specifying.
– FlailoftheLord -
Mar 25 at 14:10
Why aren't you using SnakeYaml?
– jbx
Mar 25 at 14:31
|
show 1 more comment
I am working on creating my own Custom file parser (it can read & write a .yml file or any other custom text file)
Right now I am just working on reading a pre-written file.
(Yes i have looked at several other similar issues. these didn't seem to even get close to what i'm looking for as i don't want to use an external library.
[a link] (How do I parse a YAML file?) )
However, the code I have currently does not seem to be returning the correct results.
It keeps returning an empty string, implying that the file didn't contain the values i asked for.
protected String readValue(String value)
BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource("Locale.txt")));
boolean isMultiline = false;
String multiLineCombo = "";
for (String s : reader.lines().toArray(String[]::new))
if (s.startsWith(Pattern.compile("[^a-zA-Z0-9]") + ""))
continue;
if (s.trim().startsWith(Pattern.quote("(?i)") + value + ":")) -"))
isMultiline = true;
continue;
if (isMultiline)
if (!s.contains(":"))
multiLineCombo = multiLineCombo.concat(s + "n");
continue;
else
isMultiline = false;
return multiLineCombo;
try
reader.close();
catch (Exception e)
return s.substring(s.indexOf(":"));
return "";
I'm looking for it to read simple values constructed like so:
# comments...
OwnerName: 'something here'
# more comments
# .
# yeet...
ListOfNames:
- Ann
- Brent
- Crumpled Bananas
- more values
# multiline strings like this
MultipleLines: |-
Line one
Line two
and line three
Yes, I have written the values i'm trying to pull in the target file, the values are in there, i'm just reading them wrongly.
If anybody has some tips or can help me as to what i'm doing wrong here, that would be awesome!
Edit:
Seems i need to explain why i'm attempting to create my own file reader instead of using a third-party such as SnakeYaml... Mainly because i do not want to specifically parse only YAML files, I'm looking for this as more of my own custom data storage system. The library i'm working with has a built-in yaml reader/writer, but it ignores comments, deleting them and removing any white spaces and formatting i add in. Additionally, I do not want this to be overly dependent on whether said java application has the specified libraries available. (depending on whether it has access to the Internet or not to download resources)
As such, i want to create my own, both to negate having to depend on external libraries and to increase reliability and customize-ability.
java
I am working on creating my own Custom file parser (it can read & write a .yml file or any other custom text file)
Right now I am just working on reading a pre-written file.
(Yes i have looked at several other similar issues. these didn't seem to even get close to what i'm looking for as i don't want to use an external library.
[a link] (How do I parse a YAML file?) )
However, the code I have currently does not seem to be returning the correct results.
It keeps returning an empty string, implying that the file didn't contain the values i asked for.
protected String readValue(String value)
BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource("Locale.txt")));
boolean isMultiline = false;
String multiLineCombo = "";
for (String s : reader.lines().toArray(String[]::new))
if (s.startsWith(Pattern.compile("[^a-zA-Z0-9]") + ""))
continue;
if (s.trim().startsWith(Pattern.quote("(?i)") + value + ":")) -"))
isMultiline = true;
continue;
if (isMultiline)
if (!s.contains(":"))
multiLineCombo = multiLineCombo.concat(s + "n");
continue;
else
isMultiline = false;
return multiLineCombo;
try
reader.close();
catch (Exception e)
return s.substring(s.indexOf(":"));
return "";
I'm looking for it to read simple values constructed like so:
# comments...
OwnerName: 'something here'
# more comments
# .
# yeet...
ListOfNames:
- Ann
- Brent
- Crumpled Bananas
- more values
# multiline strings like this
MultipleLines: |-
Line one
Line two
and line three
Yes, I have written the values i'm trying to pull in the target file, the values are in there, i'm just reading them wrongly.
If anybody has some tips or can help me as to what i'm doing wrong here, that would be awesome!
Edit:
Seems i need to explain why i'm attempting to create my own file reader instead of using a third-party such as SnakeYaml... Mainly because i do not want to specifically parse only YAML files, I'm looking for this as more of my own custom data storage system. The library i'm working with has a built-in yaml reader/writer, but it ignores comments, deleting them and removing any white spaces and formatting i add in. Additionally, I do not want this to be overly dependent on whether said java application has the specified libraries available. (depending on whether it has access to the Internet or not to download resources)
As such, i want to create my own, both to negate having to depend on external libraries and to increase reliability and customize-ability.
java
java
edited Mar 25 at 14:54
FlailoftheLord -
asked Mar 25 at 13:15
FlailoftheLord -FlailoftheLord -
24 bronze badges
24 bronze badges
Have you tried debugging your code? Learning how to use a debugger is probably the best thing for you to do right now.
– Tim Biegeleisen
Mar 25 at 13:19
Completely forgot about that, I will start there.
– FlailoftheLord -
Mar 25 at 13:24
At your level of experience you should definitely use a ready-made YAML parser instead of rolling your own. The YAML specification is over 70 pages long and full of horrible details and edge cases. You won't get anything right by doing it yourself. Therefore it is essential that you explain in your question why you don't want to use a third-party YAML parser.
– Roland Illig
Mar 25 at 13:53
To clarify, i was looking more into reading any filetype formatted as a .yml file, this could be a text file, .java file, anything with the correct encoding and format which i am specifying.
– FlailoftheLord -
Mar 25 at 14:10
Why aren't you using SnakeYaml?
– jbx
Mar 25 at 14:31
|
show 1 more comment
Have you tried debugging your code? Learning how to use a debugger is probably the best thing for you to do right now.
– Tim Biegeleisen
Mar 25 at 13:19
Completely forgot about that, I will start there.
– FlailoftheLord -
Mar 25 at 13:24
At your level of experience you should definitely use a ready-made YAML parser instead of rolling your own. The YAML specification is over 70 pages long and full of horrible details and edge cases. You won't get anything right by doing it yourself. Therefore it is essential that you explain in your question why you don't want to use a third-party YAML parser.
– Roland Illig
Mar 25 at 13:53
To clarify, i was looking more into reading any filetype formatted as a .yml file, this could be a text file, .java file, anything with the correct encoding and format which i am specifying.
– FlailoftheLord -
Mar 25 at 14:10
Why aren't you using SnakeYaml?
– jbx
Mar 25 at 14:31
Have you tried debugging your code? Learning how to use a debugger is probably the best thing for you to do right now.
– Tim Biegeleisen
Mar 25 at 13:19
Have you tried debugging your code? Learning how to use a debugger is probably the best thing for you to do right now.
– Tim Biegeleisen
Mar 25 at 13:19
Completely forgot about that, I will start there.
– FlailoftheLord -
Mar 25 at 13:24
Completely forgot about that, I will start there.
– FlailoftheLord -
Mar 25 at 13:24
At your level of experience you should definitely use a ready-made YAML parser instead of rolling your own. The YAML specification is over 70 pages long and full of horrible details and edge cases. You won't get anything right by doing it yourself. Therefore it is essential that you explain in your question why you don't want to use a third-party YAML parser.
– Roland Illig
Mar 25 at 13:53
At your level of experience you should definitely use a ready-made YAML parser instead of rolling your own. The YAML specification is over 70 pages long and full of horrible details and edge cases. You won't get anything right by doing it yourself. Therefore it is essential that you explain in your question why you don't want to use a third-party YAML parser.
– Roland Illig
Mar 25 at 13:53
To clarify, i was looking more into reading any filetype formatted as a .yml file, this could be a text file, .java file, anything with the correct encoding and format which i am specifying.
– FlailoftheLord -
Mar 25 at 14:10
To clarify, i was looking more into reading any filetype formatted as a .yml file, this could be a text file, .java file, anything with the correct encoding and format which i am specifying.
– FlailoftheLord -
Mar 25 at 14:10
Why aren't you using SnakeYaml?
– jbx
Mar 25 at 14:31
Why aren't you using SnakeYaml?
– jbx
Mar 25 at 14:31
|
show 1 more comment
1 Answer
1
active
oldest
votes
The startsWith Method is not used like that, maybe i think.
Here is the javadoc.
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#startsWith-java.lang.String-
If you want use regex, you can use matches method.
Here is the javadoc.
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#matches-java.lang.String-
A Pattern example link: https://www.tutorialspoint.com/java/java_regular_expressions.htm
I think there is something wrong with your usage.
A little suggestions:
1. parse line character by character.
2. make some class save your data. e.g "YAMLToken" ,"YAMLKeyValuePair", "YAMLList"
Bad English, if you save any questions, reply me
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%2f55338660%2fparsing-reading-writing-to-a-custom-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
The startsWith Method is not used like that, maybe i think.
Here is the javadoc.
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#startsWith-java.lang.String-
If you want use regex, you can use matches method.
Here is the javadoc.
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#matches-java.lang.String-
A Pattern example link: https://www.tutorialspoint.com/java/java_regular_expressions.htm
I think there is something wrong with your usage.
A little suggestions:
1. parse line character by character.
2. make some class save your data. e.g "YAMLToken" ,"YAMLKeyValuePair", "YAMLList"
Bad English, if you save any questions, reply me
add a comment |
The startsWith Method is not used like that, maybe i think.
Here is the javadoc.
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#startsWith-java.lang.String-
If you want use regex, you can use matches method.
Here is the javadoc.
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#matches-java.lang.String-
A Pattern example link: https://www.tutorialspoint.com/java/java_regular_expressions.htm
I think there is something wrong with your usage.
A little suggestions:
1. parse line character by character.
2. make some class save your data. e.g "YAMLToken" ,"YAMLKeyValuePair", "YAMLList"
Bad English, if you save any questions, reply me
add a comment |
The startsWith Method is not used like that, maybe i think.
Here is the javadoc.
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#startsWith-java.lang.String-
If you want use regex, you can use matches method.
Here is the javadoc.
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#matches-java.lang.String-
A Pattern example link: https://www.tutorialspoint.com/java/java_regular_expressions.htm
I think there is something wrong with your usage.
A little suggestions:
1. parse line character by character.
2. make some class save your data. e.g "YAMLToken" ,"YAMLKeyValuePair", "YAMLList"
Bad English, if you save any questions, reply me
The startsWith Method is not used like that, maybe i think.
Here is the javadoc.
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#startsWith-java.lang.String-
If you want use regex, you can use matches method.
Here is the javadoc.
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#matches-java.lang.String-
A Pattern example link: https://www.tutorialspoint.com/java/java_regular_expressions.htm
I think there is something wrong with your usage.
A little suggestions:
1. parse line character by character.
2. make some class save your data. e.g "YAMLToken" ,"YAMLKeyValuePair", "YAMLList"
Bad English, if you save any questions, reply me
answered Mar 25 at 13:46
hideDragonhideDragon
763 bronze badges
763 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55338660%2fparsing-reading-writing-to-a-custom-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
Have you tried debugging your code? Learning how to use a debugger is probably the best thing for you to do right now.
– Tim Biegeleisen
Mar 25 at 13:19
Completely forgot about that, I will start there.
– FlailoftheLord -
Mar 25 at 13:24
At your level of experience you should definitely use a ready-made YAML parser instead of rolling your own. The YAML specification is over 70 pages long and full of horrible details and edge cases. You won't get anything right by doing it yourself. Therefore it is essential that you explain in your question why you don't want to use a third-party YAML parser.
– Roland Illig
Mar 25 at 13:53
To clarify, i was looking more into reading any filetype formatted as a .yml file, this could be a text file, .java file, anything with the correct encoding and format which i am specifying.
– FlailoftheLord -
Mar 25 at 14:10
Why aren't you using SnakeYaml?
– jbx
Mar 25 at 14:31