Ameba Ownd

アプリで簡単、無料ホームページ作成

Java line.separator windows 7

2022.01.19 01:57




















Active Oldest Votes. Improve this answer. Try with System. Why use System. Community Bot 1 1 1 silver badge. Braj Braj 45k 5 5 gold badges 54 54 silver badges 73 73 bronze badges. How is this different from System. Braj: nothing's changed.


Still all words are in the same line. Why it's not working for you? Is this your actual code? Please share a complete code to reproduce it. Show 2 more comments. Salandur Salandur 6, 2 2 gold badges 20 20 silver badges 23 23 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. A Statement or action made with malicious intent - unless challenged.


At which point it magically transforms into "I was just funnin'" or "What's the matter, can't take a joke? Tim Holloway wrote: Your JVM is going to use the native line separator for the OS it's running under, which is usually the best solution, because the output will be most compatible with the local ecosystem. Only if you are looking to transport the output to another, incompatible OS or environment would it be sensible to override that. If you cannot do that, then changing the line.


Forum: Java in General. Mark Sojourner. Optional 'thank-you' note:. I've been playing around with the line. However if I try to use the command line switch -Dline. As you can see below, when I try to use the JVM switch, whatever I've tried so far is used literally. Any suggestions? Paul Clapham. I like Hi Mark, welcome to the Ranch! So if you use it in a Java program, it acts just as if you'd used a newline character.


But you can't expect other contexts -- such as the Windows command line -- to treat it in that way. It already is a String, unless it is null, in which case you get a NullPointerException. Yes, I just wanted to make sure that I was passing a string instead of a character to.


I should have read the documentation on the. Add a comment. Active Oldest Votes. The problem You must NOT assume that an arbitrary input text file uses the "correct" platform-specific newline separator. The solution One way to solve the problem is to use e. Scanner - has many examples of usage Scanner vs. StringTokenizer vs. Improve this answer. Community Bot 1 1 1 silver badge. Thank you for your time to answer. I tried one of the other solutions and it worked it was faster than setting up the scanners in the right places.


Since this is only a small portion of my java program, and since I know exactly what the input will be it's not an arbitrary input text file , I can assume the default newline character. I've looked at the other method that returned this input string, and it uses the platform default character. Thanks for all of your help though. Definitely didn't want the line. Also not that important but return type of System.


Thanks, this worked. I guess I just read the documentation for the split method and saw that it took a String, not understanding the difference between a regex and a String. Brian Agnew Brian Agnew k 36 36 gold badges silver badges bronze badges. Mike Baranczak Mike Baranczak 8, 6 6 gold badges 40 40 silver badges 68 68 bronze badges. I'm going to use that from now on.


You could still potentially have input which includes non-system-default line separators. This regex will catch all combinations regardless of the platform and input. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.