import java.util.Formatter;
import java.util.Scanner;
public class JavaApplication3 {
public static void main(String[] args) throws Exception
{
Formatter output = new Formatter("clients.txt"); // open the file
Scanner input = new Scanner(System.in); // reads user input
int accountNumber; // stores account number
String firstName; // stores first name
String lastName; // stores last name
double balance; // stores account balance
System.out.printf("%s\n%s\n%s\n%s\n\n",
"To terminate input, type the end-of-file indicator ",
"when you are prompted to enter input.",
"On UNIX/Linux/Mac OS X type <ctrl> d then press Enter",
"On Windows type <ctrl> z then press Enter");
System.out.printf("%s\n%s",
"Enter account number (> 0), first name, last name and balance.",
"? ");
while (input.hasNext()) // loop until end-of-file indicator
{
// retrieve data to be output
accountNumber = input.nextInt(); // read account number
firstName = input.next(); // read first name
lastName = input.next(); // read last name
balance = input.nextDouble(); // read balance
if (accountNumber > 0)
{
// write new record
output.format("%d %s %s %.2f\n", accountNumber,
firstName, lastName, balance);
} // end if
else
{
System.out.println(
"Account number must be greater than 0.");
} // end else
System.out.printf("%s %s\n%s", "Enter account number (>0),",
"first name, last name and balance.", "? ");
} // end while
output.close(); // close file
} // end main
} // end class CreateTextFile
, но при переходе к локализации файла и открытии txt-файла thre нет ничего в этом. Я использую окна, и моя проблема заключается в том, чтобы нанести ущерб файлу. Думаю, помогите мне с тем, как пишите на файл в java.tnxоткрытие файлов на JAVA
Это работает для меня, по крайней мере, на Linux. Попробуйте в Windows сейчас ... –
И это работает для меня и в Windows. –
Просьба уточнить, просматриваете ли вы файл во время работы кода или после того, как программа завершена. Если это первый, то ответ Сатья уместен, но если вы смотрите только на файл, когда программа закончилась, это не объяснит это. –