check unix fomat

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;


public class CheckUnixFormat {
	public static void main(String[] args) throws Exception {
		String fileName = "test.txt";
		String fileName2 = "test2.txt";
		System.out.println("isDosFormat:" + checkDosFormat(fileName));
		System.out.println("isDosFormat:" + checkDosFormat(fileName2));
	}

	private static boolean checkDosFormat(String fileName) throws IOException {
		boolean isDosFormat = false;
		File file = new File(fileName);
		byte[] bytes = FileUtils.readFileToByteArray(file);
		for (int i = 0; i < bytes.length; i++) {
			byte oneByte = bytes[i];
//			System.out.println(oneByte);
			if(oneByte == 13) { //\r
				isDosFormat = true;
				break;
			}
		}
		return isDosFormat;
	}
}

你可能感兴趣的:(java,unix)