我需要能夠操縱字符串中的每個字符。有人能告訴我我在這裏做錯了什麼嗎?Java 7問題逐字符讀取
import java.io.*;
public class encryptedWrite {
public static void main(String[] args) {
try {
File file = new File("code.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
BufferedReader read
= new BufferedReader(new InputStreamReader(System.in));
int charNumber = 0;
String content = read.readLine();
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
String numberString = charNumber + "";
String modCont = content.charAt(numberString);
while (!(modCont.equals("#"))) {
bw.write(modCont);
charNumber++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
我需要能夠輸出每個字符的內容code.txt。
,你得到什麼輸出,並且爲什麼錯了?我們無法讀懂你的想法。 – awksp