最近我試過編寫上面給定的標題代碼,問題是我無法獲得足夠的日期來編寫看看在我的代碼。它顯示一些錯誤,如在指定的目錄中動態創建文本文件,寫入數據,從java文件中讀取數據
它顯示無效的標記分號後tagfile.createnewfile(); 讓我們看一下代碼:
公共類WriteToFileExample {
String path = "G:"+File.separator+"Software"+File.separator+"Files";
String fname= path+File.separator+"fileName.txt";
boolean bool=false;
File f = new File(path);
File f1 = new File(fname);
try {
f1.createNewFile();
bool=f.mkdirs() ;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static final String FILENAME = "G:\\Software\\Files\\anil.txt";
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
String content = null;
String[] str = new String[100];
try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILENAME))) {
System.out.println(" enter no.of line to be inserted into file");
int k = sc.nextInt();
for (int i = 0; i <= k; i++) {
System.out.println(" enter " + i + " line data");
content = sc.nextLine();
bw.write(content);
str[i] = content;
}
System.out.println("The content present in\n
G:\ SOFTWARE \文件\ anil.txt是:「);
for (int i = 1; i <= k; i++)
System.out.println(str[i]);
} catch (IOException e) {
e.printStackTrace();
}
}
}
什麼錯誤?請在你的問題中顯示他們。 – SilverNak
也粘貼你面臨的錯誤 – Pradeep
它顯示無效的標記分號後tagfile.createnewfile(); –