LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-15-2018, 12:44 AM   #1
squall852
LQ Newbie
 
Registered: Jun 2018
Posts: 10

Rep: Reputation: Disabled
Unhappy Error when i create a file text with java


Hi all,

I'm getting some errors when I want to create a txt file with Java NetBeans. This is the error.

java.io.FileNotFoundException: /home/tony/Documents/Java (Is a directory)

Here is the code.


package manejoarchivos;

import static utileria.Archivos.*;

public class ManejoArchivos {


//Nota: ya debe estar creada la carpeta sobre la cual se va a trabar
//Y en caso necesario se deben asignar permisos de escritura a la carpeta
private static final String NOMBRE_ARCHIVO = "/home/tony/Documents/Java/";


public static void main(String[] args) {

//Crear archivo
crearArchivo(NOMBRE_ARCHIVO);
}

class.::::::::::::::::::::::::::::

package utileria;

import java.io.*;

public class Archivos {

public static void crearArchivo(String nombreArchivo)
{
File archivo = new File(nombreArchivo);
try
{
PrintWriter salida = new PrintWriter(new FileWriter(archivo));
salida.close();
System.out.println("El archivo se ha creado correctamente");
}
catch(IOException io)
{
io.printStackTrace();
}
}

I know to the exception is giving me that error but i don't know how to change the folder as not a directory.

Thank
 
Old 07-15-2018, 02:44 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
you might want to check the value of NOMBRE_ARCHIVO
 
Old 07-15-2018, 07:58 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Assign a filename to the file you want to create
Code:
crearArchivo(NOMBRE_ARCHIVO + "filename.txt");
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
file command sees regular ASCII text file as ASCII Java program text bbraml Linux - Software 6 08-30-2013 08:52 AM
[SOLVED] Want to create launcher for text-based Java program OmegaD Linux - Newbie 5 02-04-2012 08:16 PM
bash script to create text in a file or replace value of text if already exists knightto Linux - Newbie 5 09-10-2008 11:13 PM
text match pipe to file then delete from original text file create new dir automatic tr1px Linux - Newbie 6 09-10-2008 09:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration