Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

632
Views
Cómo crear un archivo .txt dentro de la carpeta del proyecto Java y escribir en él

Estoy intentando crear un archivo de texto dentro de la carpeta de mi proyecto (no dentro del src sino de la biblioteca del sistema). Ya he creado una impresión para mostrar la información adecuada en el formato correcto. Copié y pegué esto y edité "System.out.println" a "PrintWriter.println". No estoy seguro si este código es correcto aunque no muestra errores.

 try { File file = new File("SortedLists.txt"); FileWriter w = new FileWriter("SortedLists.txt"); writer = new PrintWriter(w); for(Team p: roster){ writer.println("Team Name: "+p.gettName()+", "+p.gettAbrv()); for(Riders r: p.getRide()) { writer.println(r); } writer.printf("Total Team Donations: %.2f$\n",p.getSumD()); } } catch(IOException e) { System.out.println(e.getMessage()); } finally { writer.close(); }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Si quieres saber dónde está tu archivo creado, simplemente escribe por ejemplo

 System.out.println(file.getAbsolutePath());

Además, si desea crear un archivo en una ruta relativa (por ejemplo, en una carpeta), puede hacer algo como esto:

 File folder = new File("folderName"); folder.mkdir(); // create a folder in your current work space File file = new File(folder, "fileName.txt"); // put the file inside the folder file.createNewFile(); // create the file
over 4 years ago · Santiago Trujillo Report

0

Para establecer la ruta del archivo, cree el archivo de la siguiente manera:

String fileLocation = rutaAbsolutaAlArchivo;

Archivo archivo = nuevo archivo (ubicación);

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Virtual assistant