集册 Java实例教程 使用PrintWriter写入文件

使用PrintWriter写入文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

468
使用PrintWriter写入文件



import java.io.FileNotFoundException;// 来自 n  o  w  j  a  v  a . c o m

import java.io.PrintWriter;

import java.util.Scanner;


public class Ejercicio1 {


  public static void Main(String[] args){

    Scanner sc = new Scanner(System.in);

    String text;

    PrintWriter result = null;

    try{

      result = new PrintWriter("a.txt");

      System.out.println("introduce texto:");// 来 自 N o w J a v a . c o m - 时  代  Java

      text = sc.nextLine();

      while (text.compareTo("fin") != 0) {

        result.println(text);

        text = sc.nextLine();

      }

    
展开阅读全文