Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个文本文件,其中包含一个单词“fish”,但单词后面会有空格。无论如何我可以把鱼这个词作为一个变量而不是空格吗?
Scanner in = new Scanner(new File("path_to_file.txt")); String var = in.next(); var = var.trim(); in.close();
不是最有效的方法,而是最简单的方法之一。
字符串文本 = File.ReadAllText("path_to_file.txt").trim();