<p>Am I correct in assuming that the only difference between &quot;windows files&quot; and &quot;unix files&quot; is the linebreak?</p>
<p>We have a system that has been moved from a windows machine to a unix machine and are having troubles with the format.</p>
<p>I need to automate the translation between unix/windows before the files get delivered to the system in our &quot;transportsystem&quot;. I'll probably need something to determine the current format and something to transform it into the other format.
If it's just the newline thats the big difference then I'm considering just reading the files with the java.io. As far as I know, they are able to handle both with readLine. And then just write each line back with</p>
<pre><code>while (line = readline)
    print(line + NewlineInOtherFormat)
....
</code></pre>
<hr />
<h2>Summary:</h2>
<blockquote>
<p><a href="https://stackoverflow.com/users/1908/samjudson">samjudson</a>:</p>
<blockquote>
<p><i>This is only a difference in text files, where UNIX uses a single Line Feed (LF) to signify a new line, Windows uses a Carriage Return/Line Feed (CRLF) and Mac uses just a CR.</i></p>
</blockquote>
<p>to which <a href="https://stackoverflow.com/users/1612/cebjyre">Cebjyre</a> elaborates:</p>
<blockquote>
<p><i>OS X uses LF, the same as UNIX - MacOS 9 and below did use CR though</i></p>
</blockquote>
<p><a href="https://stackoverflow.com/users/1870/mo">Mo</a></p>
<blockquote>
<p><i>There could also be a difference in character encoding for national characters. There is no &quot;unix-encoding&quot; but many linux-variants use UTF-8 as the default encoding. Mac OS (which is also a unix) uses its own encoding (macroman). I am not sure, what windows default encoding is.</i></p>
</blockquote>
<p><a href="https://stackoverflow.com/users/304/mcdowell">McDowell</a></p>
<blockquote>
<p><i>In addition to the new-line differences, the byte-order mark can cause problems if files are treated as Unicode on Windows.</i></p>
</blockquote>
<p><a href="https://stackoverflow.com/users/1820/cheekysoft">Cheekysoft</a></p>
<blockquote>
<p><i>However, another set of problems that you may come across can be related to single/multi-byte character encodings. If you see strange unexpected chars (not at end-of-line) then this could be the reason. Especially if you see square boxes, question marks, upside-down question marks, extra characters or unexpected accented characters.</i></p>
</blockquote>
<p><a href="https://stackoverflow.com/users/1000/sadie">Sadie</a></p>
<blockquote>
<p><i>On unix, files that start with a . are hidden. On windows, it's a filesystem flag that you probably don't have easy access to. This may result in files that are supposed to be hidden now becoming visible on the client machines.</p>
<p>File permissions vary between the two. You will probably find, when you copy files onto a unix system, that the files now belong to the user that did the copying and have limited rights. You'll need to use chown/chmod to make sure the correct users have access to them.</i></p>
</blockquote>
</blockquote>
<p>There exists tools to help with the problem:</p>
<blockquote>
<p><a href="https://stackoverflow.com/users/755/pauldoo">pauldoo</a></p>
<blockquote>
<p><i>If you are just interested in the content of text files, then yes the line endings are different. Take a look at something like dos2unix, it may be of help here.</i></p>
</blockquote>
<p><a href="https://stackoverflow.com/users/1820/cheekysoft">Cheekysoft</a></p>
<blockquote>
<p><i>As pauldoo suggests, tools like dos2unix can be very useful. Note that these may be on your linux/unix system as fromdos or tofrodos, or perhaps even as the general purpose toolbox recode.</i></p>
</blockquote>
</blockquote>
<p>Help for java coding</p>
<blockquote>
<p><a href="https://stackoverflow.com/users/1820/cheekysoft">Cheekysoft</a></p>
<blockquote>
<p><i>When writing to files or reading from files (that you are in control of), it is often worth specifying the encoding to use, as most Java methods allow this. However, also ensuring that the system locale matches can save a lot of pain</i></p>
</blockquote>
</blockquote>

[{'answer_id': 17649, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 5, 'selected': True, 'text': '<p>This is only a difference in text files, where UNIX uses a single Line Feed (LF) to signify a new line, Windows uses a Carriage Return/Line Feed (CRLF) and Mac uses just a CR.</p>\n\n<p>Binary files there should be no difference (i.e. a JPEG on a windows machine will be byte for byte the same as the same JPEG on a unix box.)</p>\n'}, {'answer_id': 17650, 'author': 'Mo.', 'author_id': 1870, 'author_profile': 'https://Stackoverflow.com/users/1870', 'pm_score': 2, 'selected': False, 'text': '<p>There could also be a difference in character encoding for national characters. There is no "unix-encoding" but many linux-variants use UTF-8 as the default encoding. Mac OS (which is also a unix) uses its own encoding (macroman). I am not sure, what windows default encoding is.</p>\n\n<p>But this could be another source of trouble (apart from the different linebreaks).</p>\n\n<p>What are your problems? The linebreak-related problems can be easily corrected with the programs dos2unix or unix2dos on the unix-machine</p>\n'}, {'answer_id': 17654, 'author': 'pauldoo', 'author_id': 755, 'author_profile': 'https://Stackoverflow.com/users/755', 'pm_score': 2, 'selected': False, 'text': '<p>If you are just interested in the content of text files, then yes the line endings are different.  Take a look at something like <a href="http://www.linuxcommand.org/man_pages/dos2unix1.html" rel="nofollow noreferrer">dos2unix</a>, it may be of help here.</p>\n\n<p>(Of course there are many other things that make unix and windows files different, but I don\'t think you\'re interested in those other differences right now.)</p>\n'}, {'answer_id': 17659, 'author': 'McDowell', 'author_id': 304, 'author_profile': 'https://Stackoverflow.com/users/304', 'pm_score': 1, 'selected': False, 'text': '<p>In addition to the new-line differences, the <a href="http://en.wikipedia.org/wiki/Byte_Order_Mark" rel="nofollow noreferrer">byte-order mark</a> can cause problems if files are treated as Unicode on Windows.</p>\n'}, {'answer_id': 17675, 'author': 'Cheekysoft', 'author_id': 1820, 'author_profile': 'https://Stackoverflow.com/users/1820', 'pm_score': 1, 'selected': False, 'text': '<p>As pauldoo suggests, tools like dos2unix can be very useful. Note that these may be on your linux/unix system as <strong>fromdos</strong> or <strong>tofrodos</strong>, or perhaps even as the general purpose toolbox <strong>recode</strong>.</p>\n\n<p>However, another set of problems that you may come across can be related to single/multi-byte character encodings. If you see strange unexpected chars (not at end-of-line) then this could be the reason. Especially if you see square boxes, question marks, upside-down question marks, extra characters or unexpected accented characters.</p>\n\n<p>Running the command <strong>locale</strong> on your *nix box will tell you what the system locale is. If this is different to the encoding used in the text files that have been transferred over from the windows machine, then this can sometimes cause issues, depending on the usage of those files. You can use the very powerful <strong>recode</strong> command to try and convert between the different charsets as well as any line ending issues. <strong>recode -l</strong> will show you all of the formats and encodings that the tool can convert between. It is likely to be a VERY long list.</p>\n\n<p>When writing to files or reading from files (that you are in control of), it is often worth specifying the encoding to use, as most Java methods allow this. However, also ensuring that the system locale matches can save a lot of pain.</p>\n'}, {'answer_id': 17678, 'author': 'Marcus Downing', 'author_id': 1000, 'author_profile': 'https://Stackoverflow.com/users/1000', 'pm_score': 2, 'selected': False, 'text': "<p>In addition to the answers given, you may find issues with the different file systems:</p>\n\n<ul>\n<li><p>On unix, files that start with a <strong>.</strong> are hidden. On windows, it's a filesystem flag that you probably don't have easy access to. This may result in files that are supposed to be hidden now becoming visible on the client machines.</p></li>\n<li><p>File permissions vary between the two. You will probably find, when you copy files onto a unix system, that the files now belong to the user that did the copying and have limited rights. You'll need to use <strong>chown/chmod</strong> to make sure the correct users have access to them.</p></li>\n</ul>\n"}]
['https://Stackoverflow.com/questions/17645', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/86/']