我正在使用BufferedWriter
将字符串写入这样的文件:
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
String myname = "JOHN DOE MAXWELL";
String myotherName = "MELCHIZEDEK NEBUCHARDINEZZAR";
String mylocation = "SOUTH EAST";
String myotherlocation = "SOUTH WEST";
File f = new File("MyFile.txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
bw.write(myname + " " + mylocation);
bw.newLine();
bw.write(myothername + " " + myotherlocation);
bw.close();
}
}
我需要这样写mylocation
,无论字符串的长度如何,都不会影响myname
的开始位置。mylocation
请协助。
我的输出应该是:
JOHN DOE MAXWELL SOUTH EAST
MELCHIZEDEK NEBUCHARDI SOUTH WEST