⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demotextfileio.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
import java.io.*;
import java.util.*;

/**	Example of a program that writes to a text file, and then
	reads from the file and displays the results on the console. */
public class DemoTextFileIO 
{
	public static void main (String[] args) throws IOException
	{
		PrintWriter myOutFile = new PrintWriter(new FileWriter("myTextFile.txt")); 
		myOutFile.print(7); 
		myOutFile.print("     " + 6 + "\n"); 
		myOutFile.println("Hello World"); 
		myOutFile.print(123.456); 
		myOutFile.close();

		BufferedReader myInFile = new BufferedReader(new FileReader("myTextFile.txt")); 
		String currentLine = myInFile.readLine();
		StringTokenizer wordFinder = new StringTokenizer (currentLine);
		while (wordFinder.hasMoreTokens())
		{
			int a = Integer.parseInt(wordFinder.nextToken());
			System.out.println(a);
		}
		String b = myInFile.readLine();
		currentLine = myInFile.readLine();
		float c = Float.parseFloat(currentLine);
		myInFile.close();
		System.out.println(b + "\n" + c);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -