因此,我的任务是用文本文件进行外部合并排序。我也应该一次最多只有3个字符串。
这就是我的合并方法的样子:
public static void mergeSortExternal(File c) throws IOException {
int n = lineCount(c);
int mid = n / 2;
Scanner s = new Scanner(c);
s.useDelimiter("[.,:;()?!\"\\s]+");
File a = new File(dir +
我的班级:
public class Test{
public static void writeSmth() {
try {
BufferedWriter out = new BufferedWriter(
new FileWriter("one.txt"));
out.write("content");
} catch (IOException e) {
e.printStackTrace();
}
我正在尝试制作一个具有工作高分机制的游戏,我正在使用java.io.BufferedWriter来写入一个高分文件。我没有对高分进行加密,我使用Slick2D和LWJGL进行渲染和用户输入。程序执行以下代码:
FileWriter fstream = new FileWriter("res/gabjaphou.txt");
BufferedWriter writer = new BufferedWriter(fstream);
writer.write(score); // score is an int value
writer.close(); // gotta sa
我正在尝试用Java将一些数据输出到文件中,我不明白为什么当我运行这段代码时……
try {
File file = new File("demo.txt");
BufferedWriter out = new BufferedWriter(new FileWriter(file));
int i = 127;
int j = 128;
System.out.println(Integer.toHexString(i));
System.out.println(Integer.toHexString(j));
out.wr
我运行这段代码,得到的结果是"File written !“当我打开文件查看它时,写的每一件事都没有任何意义。您可以理解我想要在文件中写入012345678910。除了buffW.write(k);,还有没有其他方法可以写入文件。我还犯了什么其他错误吗?
package thema4_create_write_read_file;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
public class FW {
public static void main(S
我正在试着写一个来自JTextArea的String(冗长但包装好)。当字符串打印到控制台时,格式与在Text Area中相同,但当我使用BufferedWriter将其写入文件时,它将在单行中写入String。
下面的代码片段可以重现它:
public class BufferedWriterTest {
public static void main(String[] args) throws IOException {
String string = "This is lengthy string that contains many words. So\
当我运行以下代码时:
int i = 0
try {
fstream = new FileWriter(filename);
BufferedWriter out = new BufferedWriter(fstream);
while (i < 100) {
out.write("My Name is Bobby Bob");
out.write(i);
out.newLine();
i++;
}
out.flush();
我尝试了一些基本的Java I/O操作,我尝试运行以下代码:
public static void main(String[] args) {
File file = new File("fileWrite2.txt"); // create a File object
try {
FileWriter fr = new FileWriter(file);
PrintWriter pw = new PrintWriter(file); // create a PrintWriter that will send its output to a
我正在做一个程序,我需要添加一个随机的6位数字ids的列表到一个文件。目前,每当我运行程序的这一部分,任何东西都不会添加到文件中。我到底做错了什么,这样代码才不会写到文件中?我检查并确保所有的随机数都是绝对生成的。
static HashSet<Integer> idHashList =
new HashSet<>();
public static void createIds(){
File writeId = new File("peopleIDs.txt");
try {
FileWriter f
我正在编写一个程序,该程序获取用户输入,然后写入一个名为userStrings.txt的输出文件。我还试图在用户输入“完成”后停止处理,但我不知道如何完成这一任务。
这是我的代码:
import java.io.*;
import java.util.Scanner;
public class Murray_A04Q2 {
public static void main(String[] args) throws IOException {
// Name of the file
String fileName = "userStrings.txt
试图保留我的字符串格式。当我打开我的.txt文件时,所有的东西都会被写到一行。
String page = t.toString(); //this is my formatting String
String fileName = t.getSymbol(); //just helps me name the file (not important)
File file = new File("C:/Users/user1234212/desktop/folder1" + fileName + ".txt"); //not im
我试图通过不同的类写入一个文本文件。我从主类打开了文本文件:
public static void main( String[] args ) throws Exception {
BufferedWriter writer = new BufferedWriter(new FileWriter("src/t1.txt"));
Parser.getParseTree().print(); // where I called the method
writer.close();
}
这是来自另一个类的print()方法:
public stat
我有一个带有word1**word2格式的单词列表
我想把第一个词放在字符串的末尾,比如word2 - word1。
如何在不使用**的情况下拆分第一个单词,并在粘贴单词的末尾添加一个-?
我希望让这些行从文件words.txt中读取,并创建一个新的new-words.txt文件。
例如,我希望Bibi**Tina在Tina - Bibi中被转换
编辑:我尝试了一个新的代码。现在我在控制台上得到了正确的输出,但是新创建的文件是空的。
import java.io.*;
import java.util.*;
public class Main {
public static
我在尝试用字符串写入文本文件时遇到了一个奇怪的问题,这些字符串包含像"ñ",“á”这样的字符。诸若此类。让我先给你看我的一小段代码:
import java.io.*;
public class test {
public static void main(String[] args) throws Exception {
String content = "whatever";
int c;
c = System.in.read();
content = content + (char)c;
我正在尝试从JOptionPane获取输入,并使用FileWriter class.To将用户键入的内容存储到文本文件中。确保来自用户键入的输入已存储,我编写了一个system.out,并且显示了我在JOptionPane中键入的内容。不幸的是,当我打开.txt文件时,我输入的任何内容都不会出现!顺便说一下,我输入的文件路径是正确的。
这是我的代码。帮帮我!
String playername = JOptionPane.showInputDialog("What Will Be Your Character's Name?");
System.out.println(