Ayuda con Filewriter, PrintWriter y FileReader con metodos
hola a tod@s
bueno tengo un problemilla, resulta que en la uni me estan enseñando a programar en java, y el ejercicio de esta semana es crear varios programas en un solo proyecto. tenemos que escrivir y leer archivos. me gustaria organizarlos por metodos pero no se.
el codigo es este:
package ejercicio20;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Rom
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
}
public static void apartadoA() throws IOException {
try {
FileWriter fw = new FileWriter("apartadoa.txt");
PrintWriter pw = new PrintWriter(fw);
pw.print("Hola que tal estoy escriviendo texto en un fichero");
pw.close();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void apartadoB() {
}
public static void apartadoC() {
java.util.Scanner scan = new java.util.Scanner(System.in);
try {//** while has next
String a = scan.nextLine();
FileWriter fw = new FileWriter("Fichero.txt");
PrintWriter pw = new PrintWriter(fw);
pw.println(a);
pw.close();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
De esta manera no funcionan, yaque no estan en el metodo main. como puedo hacerlo??
bueno tengo un problemilla, resulta que en la uni me estan enseñando a programar en java, y el ejercicio de esta semana es crear varios programas en un solo proyecto. tenemos que escrivir y leer archivos. me gustaria organizarlos por metodos pero no se.
el codigo es este:
package ejercicio20;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Rom
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
}
public static void apartadoA() throws IOException {
try {
FileWriter fw = new FileWriter("apartadoa.txt");
PrintWriter pw = new PrintWriter(fw);
pw.print("Hola que tal estoy escriviendo texto en un fichero");
pw.close();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void apartadoB() {
}
public static void apartadoC() {
java.util.Scanner scan = new java.util.Scanner(System.in);
try {//** while has next
String a = scan.nextLine();
FileWriter fw = new FileWriter("Fichero.txt");
PrintWriter pw = new PrintWriter(fw);
pw.println(a);
pw.close();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
De esta manera no funcionan, yaque no estan en el metodo main. como puedo hacerlo??
