如何将文件从Dos转换为Unix [英] How to convert files from Dos to Unix

查看:620
本文介绍了如何将文件从Dos转换为Unix的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个要从Dos转换为Unix的文件.是否有任何API或方法可以帮助我做到这一点?

I am having several files which I want to convert from Dos to Unix. Is there any API or method which will help me to do this?

推荐答案

有些Linux工具可以做到这一点(

There are linux tools that can do this (dos2unix for example).

在Java中,可以使用

In Java it can be done with String.replaceAll().

DOS使用\r\n进行行终止,而UNIX使用单个\n.

DOS uses \r\n for line termination, while UNIX uses a single \n.

String unixText = windowsText.replaceAll("\r\n", "\n"); // DOS2UNIX

因此,不存在,没有API.是的,这很容易.

So no, no API exists. Yes, it is dead easy.

这篇关于如何将文件从Dos转换为Unix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆