我已经创建了几种逐字编辑文件文本的方法,但现在需要使用printStream来创建一个新文件,其中包含更新的文本。我已经对printStream做了一些研究,但仍然不太明白如何做到这一点。这是我的代码:
public static void main(String[] args) throws FileNotFoundException {
File jaws = new File("JawsScript.txt");
Scanner in = new Scanner(jaws);
while (in.hasNext()) {
String word = in.next();
PrintStream out =
new PrintStream(new File("stuff.txt"));
System.out.println(convert(word));
} 方法“转换”是一个调用所有其他方法并将所有更改应用于文本中的单个字符串的方法:
//Applies all of the methods to the string
public static String convert(String s) {
String result = "";
result = rYah(s);
result = rWah(result);
result = transform(result);
result = apend(result);
result = replace(result);
return result;
}我基本上只是想知道如何使用printStream将“转换”应用于文本,并将更新后的文本打印到新文件中。
发布于 2019-12-13 21:33:43
import java.io.PrintStream;
public class Main2{
public static void main(String[]args){
String str = " The Big House is";
PrintStream ps = new PrintStream(System.out);
ps.printf("My name is : %s White", str);
ps.flush();
ps.close();
}
}产出是:大房子是白色的
使用PrintStream的另一种方式是..。
CharSequence cq = "The Big House is White";
PrintStream ps = new PrintStream(System.out);
ps.append(cq);
ps.flush();
ps.close();
}
}https://stackoverflow.com/questions/49582205
复制相似问题