java - 另一个java.io.FileNotFoundException(系统找不到指定的文件)线程

标签 java file text path

我创建了一个基本的记事本文本文件(例如,text-file.txt),并尝试将此文件放置在多个文件路径中以便我的代码进行检索,但我似乎无法让它工作。基本上,我想获取 text-file.txt 的内容并创建第二个文件,其中所有内容全部大写。

这是我的代码:

package abc123;

import java.util.Scanner;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

public class abc123
{
        public static void main (String [] args) throws IOException
        {
                Scanner in = new Scanner(System.in); 

            System.out.print("Please provide the name of your input file: ");
            String inFileName = in.nextLine();
            System.out.print("Please indicate what you'd like to name your output file: ");
            String outFileName = in.nextLine();

            FileReader reader = new FileReader(inFileName);
            PrintWriter writer = new PrintWriter(outFileName); 
            Scanner fileReader = new Scanner(reader); 

            while(fileReader.hasNext())
            {
                    String line = fileReader.nextLine();
                    line = line.toUpperCase();
                    writer.println(line);
            }

            fileReader.close();
            writer.close();

            System.out.println("The process is now complete. Please check your output file. Thank you.");
        }
}

我是一个 Java 新手,所以我现在可以掌握的一个简单的解决方案(和往常一样的评论)将非常有帮助。谢谢!

最佳答案

如果该文件与您的 java 类不在同一文件夹中,则必须提供 java 完整路径才能查找该文件。确保您还键入了文件的扩展名,例如“.txt”。

关于java - 另一个java.io.FileNotFoundException(系统找不到指定的文件)线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36367168/

相关文章:

java - 处理代码不起作用(线程、draw()、noLoop() 和loop())

c# - 将 java sha512crypt 转换为 c#

java - Google play 的多个 sha1 key

python - 根据条件更改多个文件的名称

regex - 删除所有包含 x 数量的字符串

c - 好的文本分词器库

javascript - 将文本字符串转换为 JSON 格式 - Javascript

java - ant buildfile + javadoc -- 包括 javadoc 底部的 html

wpf - 在 WPF 中显示图像而不打开文件

python - 在 ipython 解释器中执行文件