文本文档变成java格式_如何将txt文件改成java文件?

展开全部

调用时,类名.readFile("d:/1.txt");即可:public static String[] readFile(String sourceFileName) throws IOException

{

String[] array = null;

Set result = new HashSet();

String lineText;

BufferedReader reader = null;

try

{

File sourceFile = new File(sourceFileName);

reader = new BufferedReader(new FileReader(sourceFile));

while ((lineText = reader.readLine()) != null)

{

//验证是否合法62616964757a686964616fe4b893e5b19e31333337396232

if(!"".equals(lineText.trim()))

{

result.add(lineText.trim());

}

}

}

catch (FileNotFoundException e)

{

//这里由于文件基本不太可能找不到,将此类异常忽略

throw new RuntimeException(e);

}

finally

{

if (reader != null)

{

try

{

reader.close();

}

catch (IOException e)

{

throw new RuntimeException(e);

}

}

}

return result.toArray();

}


版权声明:本文为weixin_28909303原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。