Java - Crear varios Archivos .txt

 
Vista:
sin imagen de perfil
Val: 25
Ha aumentado su posición en 1146 puestos en Java (en relación al último mes)
Gráfica de Java

Crear varios Archivos .txt

Publicado por andre (15 intervenciones) el 17/07/2021 10:19:01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Tengo este código como puedo hacer para que me genere cartas personalizadas con este archivo "Cartas.txt" a todos los estudiantes que tengan 0  una carta por estudiante y que en la carta conste el nombre del estudiante y de igual manera que el archivo se guarde con el nombre del estudiante
 
adjunto el archivo txt de la carta y el archivo csv
este es el link: https://drive.google.com/drive/folders/1cqzsheVlH61TD5nUkglCOd-7wzhkKrxq?usp=sharing
 
 
public class CartaStudiantes {
 
	public static void main(String[] args) throws IOException {
 
		String[][] datosCSV = deCSVaMatriz("C:\\Users\\US\\Desktop\\Student Assignment Scores (2).csv");
 
		if (datosCSV != null) {
 
 
			for (int fila = 1; fila < datosCSV.length; fila++) {
 
				if (datosCSV[fila][0] != null) {
					for (int col = 0; col < datosCSV[fila].length; col++) {
						System.out.printf(datosCSV[fila][col] + " ");
					}
					System.out.println();
				}
			}
 
			System.out.println("\n\n\t\ Assignaturas 0\n");
			mostrarAsignaciones0(datosCSV);
 
		}
		else
			System.out.printf("\r\n Unable to get CSV data");
 
		System.out.printf("\n\n\t\tprograma finalizado");
 
	}
 
	private static String[][] deCSVaMatriz(String rutaCSV) {
		try {
			Scanner lector = new Scanner(new File(rutaCSV));
			String[][] matriz = new String[30][7];
			int fila = 0;
 
			String linea = lector.nextLine();
 
			 String[] parts1 = linea.split(",");
			 System.out.println(parts1[0]+" "+parts1[1]+" "+parts1[2]+" "+parts1[3]+" "+parts1[4]+" "+parts1[5]+" "+parts1[6]);
 
			 System.out.println("-----------------------------------------------------------------------------");
			while (lector.hasNextLine()) {
 
				matriz[fila] = linea.split(",");
				fila++;
				linea = lector.nextLine();
			}
			lector.close();
 
			return matriz;
		} catch (FileNotFoundException e) {
			System.out.printf("\r\n No file found: " + rutaCSV);
			return null;
		}
 
 
	}
	private static void mostrarAsignaciones0(String[][] matriz) throws IOException {
		BufferedWriter escritor = new BufferedWriter(new FileWriter("C:\\Users\\US\\Desktop\\Warnings1.txt"));
		boolean continuar=true;
		while (continuar=true) {
		 System.out.println("Creando Cartas Para");
		for (int fila = 1; fila < matriz.length; fila++) {
			String nombre = matriz[fila][0];
 
 
			if (nombre != null)
 
				for (int col = 0; col < matriz[fila].length; col++)
 
					if (matriz[fila][col].equals("0")) {
 
 
						System.out.println(nombre );
						escritor.write(nombre);
						escritor.newLine();
					}
 
		}
 
		}
 
 
		escritor.close();
 
	}
 //Intente con este método peor me guarda un solo archivo en blanco
 
 
	//public static void LeerCarta() throws IOException {
 
	//	Scanner lector = new Scanner(new File("C:\\Users\\US\\Desktop\\Carta.txt"));
	//	String linea = lector.nextLine();
	//	FileWriter fichero=new FileWriter("C:\\Users\\US\\Desktop\\Cartas.txt");
	//	while (lector.hasNextLine()) {
		//	fichero.write("La contraseña... " + linea + " ...es: ");
//
	//		linea = lector.nextLine();
 
	//	}
	//	fichero.close();
	//	//System.out.println("Escanenado contraseña");
//}
	}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 25
Ha aumentado su posición en 1146 puestos en Java (en relación al último mes)
Gráfica de Java

Crear varios Archivos .txt

Publicado por ander (15 intervenciones) el 17/07/2021 20:52:04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
le actualice este metodo y ya me concatena el nombre del estudiante con la carta pero en un solo archivo como puedo hacer para que se me guarde en diferentes archivos por alumno
private static void mostrarAsignaciones0(String[][] matriz) throws IOException {
		BufferedWriter escritor = new BufferedWriter(new FileWriter("C:\\Users\\US\\Desktop\\Warnings1.txt"));
 
		BufferedReader lector = new BufferedReader(new FileReader("C:\\Users\\US\\Desktop\\Warning Letter to Student -.txt"));
		String linea = lector.readLine();
 
		boolean continuar=true;
		//while (continuar=true) {
		 System.out.println("Creando Cartas Para");
		for (int fila = 1; fila < matriz.length; fila++) {
			String nombre = matriz[fila][0];
 
 
			if (nombre != null)
 
				for (int col = 0; col < matriz[fila].length; col++)
 
					if (matriz[fila][col].equals("0")) {
										System.out.println(nombre );
						escritor.write(nombre+linea);
						escritor.newLine();
 
						continuar=false;
					}
 
		//}
 
		}
 
 
		escritor.close();
 
	}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar