ficheirodetexto.java

来自「Its a project that i create. The progra」· Java 代码 · 共 65 行

JAVA
65
字号
import java.io.*;

public class FicheiroDeTexto {

	// Atributos
	private BufferedReader fR;
	private BufferedWriter fW;

	public void abreLeitura (String nomeDoFicheiro) throws IOException {
		fR = new BufferedReader(new FileReader(nomeDoFicheiro));
	}

	public void abreEscrita (String nomeDoFicheiro) throws IOException {
		fW = new BufferedWriter(new FileWriter(nomeDoFicheiro));
	}

	public String lerLinha () throws IOException {
		return fR.readLine();	
	}

	public int[] lerNumeroInt () throws IOException {
		int[] result = new int[2];
		String st = fR.readLine();
		if (st != null) {
			result[0] = 0;
			result[1] = Integer.parseInt(st);
		} else result[0] = -1;
		return result;
	}

	public void escreverLinha (String linha) throws IOException {
		fW.write(linha,0,linha.length());
		fW.newLine();
	}

	public void escreverNumero (int num) throws IOException {
		String st = "";
		st = st.valueOf(num);
		escreverLinha(st);
	}

	public double [] lerNumeroDouble () throws IOException {
		double [] result = new double [2];
		String st = fR.readLine();
		if (st != null) {
			result[0] = 0;
			result[1] = Double.parseDouble (st);
		} else result[0] = -1;
		return result;
	}

	public void escreverNumero (double num) throws IOException {
		String st = "";
		st = st.valueOf(num);
		escreverLinha(st);
	}

	public void fechaLeitura () throws IOException {
		fR.close();
	}

	public void fechaEscrita () throws IOException {
		fW.close();
	}
}

⌨️ 快捷键说明

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