如何将txt文件改成java文件?
答案:7 悬赏:80
解决时间 2021-01-17 00:48
- 提问者网友:树红树绿
- 2021-01-16 05:59
如何将txt文件改成java文件?
最佳答案
- 二级知识专家网友:第幾種人
- 2021-01-16 07:18
调用时,类名.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)
{
//验证是否合法
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();
}
public static String[] readFile(String sourceFileName) throws IOException
{
String[] array = null;
Set
String lineText;
BufferedReader reader = null;
try
{
File sourceFile = new File(sourceFileName);
reader = new BufferedReader(new FileReader(sourceFile));
while ((lineText = reader.readLine()) != null)
{
//验证是否合法
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();
}
全部回答
- 1楼网友:西岸风
- 2021-01-16 11:49
把隐藏的后缀名显示出来 改成java
- 2楼网友:怀裏藏嬌
- 2021-01-16 11:35
直接把后缀名改成.java就行了,然后输入命令编译
- 3楼网友:行雁书
- 2021-01-16 10:56
改后缀名
- 4楼网友:你可爱的野爹
- 2021-01-16 09:37
在任意文件夹下,新建一个 text 文本文档,然后重命名为 XXX.java(以 .java 为后缀的命名)<这里需要注意,可能有的电脑默认为隐藏后缀的文件,这时后缀不要设为隐藏,并要删除文扩展名>,在cmd下运行时,要先找对文件所在路径
- 5楼网友:轮獄道
- 2021-01-16 08:39
直接改后缀名,“.txt”改成“.java”
- 6楼网友:往事隔山水
- 2021-01-16 07:34
打开我的电脑,或者任意文件夹,然后菜单 工具/文件夹选项/查看/ 高级设置里隐藏已知文件的扩展名的勾去掉,然后你就能看到文件的后缀名了,修改名字就好了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息