| | |
Putting files in Jlist
![]() |
•
•
Join Date: Mar 2007
Posts: 27
Reputation:
Solved Threads: 0
ListFile class takes care of writing the files to Jlist
Basically there is a Jlist in my GUI and I want it to display the files stored in my user folder.
But for some reason it doesnt work the Jlist say that there is Null file.
[code = java]
package milestonemyworkspace;
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;
import java.lang.reflect.Array;
/**
* Handles the account details and login access.
*
* @author Abimar Skrubel
* @version 1.0
*/
public class User
{
private String name; //Username
private String password; //The Special Picture
private boolean access;
public User()
{
}
/**
* Sets the username
*/
public void setName(String name)
{
this.name = name;
}
/**
* Sets the password
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* Gets the username
*/
public String getName()
{
return name;
}
/**
* Gets the password
*/
public String getPassword()
{
return password;
}
/*
* Saves user information to a text file
*/
public void saveUser()
{
File nameDir = new File("H:/SDI/MileStoneMyWorkSpace/MileStoneMyWorkSpace/users/" + name);
nameDir.mkdir(); //creates directory
File fileo = new File("H:/SDI/MileStoneMyWorkSpace/MileStoneMyWorkSpace/users/" + name + ".dat");
try
{
DataOutputStream ou = new DataOutputStream(new FileOutputStream(fileo));
ou.writeBytes(name + " , " + password);
ou.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
/**
* What is called after getting username and password for your account right
*/
public void login()
{
}
/**
* Reads the users account Information from the text file and matches it to user input to see if it is correct
*/
public void loadUser()
{
BufferedReader reader = null;
try{
reader = new BufferedReader(
new FileReader("H:\\SDI\\MileStoneMyWorkSpace\\MileStoneMyWorkSpace\\users\\" + name + ".dat"));
System.out.println("Results...");
String line;
line = reader.readLine();
while(line != null) {
System.out.println(line);
if(line.equals(name + " , " + password))
{
System.out.println("Right u aree ");
access = true;
}
else
{
System.out.println("WRONGGG");
access = false;
}
line = reader.readLine();
}
System.out.println();
}
catch(FileNotFoundException e){
System.out.println("Unable to find the file " + name + ".dat" );
}
catch(IOException e) {
System.out.println("Error found reading the file: " + name + ".dat" );
}
finally{
if(reader != null) {
//Catch any exception but nothing can be done about it.
try{
reader.close();
}
catch(IOException e) {
System.out.println("Error on closing: " + name + ".dat");
}
}
}
}
/**
* Gets user access
* If user input it's correct password and username it has access
* @return boolean
*/
public boolean getAccess()
{
return access;
}
}
package milestonemyworkspace;
import java.util.*;
import java.io.*;
/**
* Lists files in fileList
*
* @author Abimar Skrubel
* @version 1.0
*/
public class ListFiles
{
private ArrayList files;
private User user;
public ListFiles()
{
files = new ArrayList();
User user = new User();
}
//Write files to array list object
public void writeFiles()
{
user.getName();
try{
File fileo = new File(
"H:/SDI/MileStoneMyWorkSpace/MileStoneMyWorkSpace/users/" + user.getName() +
"/fileList.dat");
DataOutputStream ou = new DataOutputStream(new FileOutputStream(fileo));
ou.writeBytes(user.getName());
ou.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
//read files to put in J list
public void readFiles()
{
BufferedReader reader = null;
try{
reader = new BufferedReader(
new FileReader("H:\\SDI\\MileStoneMyWorkSpace\\MileStoneMyWorkSpace\\users\\" + user.getName() + "fileList.dat"));
System.out.println("Results...");
String line;
line = reader.readLine();
while(line != null) {
System.out.println(line);
line = reader.readLine();
}
System.out.println();
}
catch(FileNotFoundException e){
System.out.println("Unable to find the file " + user.getName() + ".dat" );
}
catch(IOException e) {
System.out.println("Error found reading the file: " + user.getName() + ".dat" );
}
finally{
if(reader != null) {
//Catch any exception but nothing can be done about it.
try{
reader.close();
}
catch(IOException e) {
System.out.println("Error on closing: " + user.getName() + ".dat");
}
}
}
}
public Object getFiles()
{
return files;
}
}
package milestonemyworkspace;
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;
import java.lang.reflect.Array;
/**
* Handles the account details and login access.
*
* @author Abimar Skrubel
* @version 1.0
*/
public class User
{
private String name; //Username
private String password; //The Special Picture
private boolean access;
public User()
{
}
/**
* Sets the username
*/
public void setName(String name)
{
this.name = name;
}
/**
* Sets the password
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* Gets the username
*/
public String getName()
{
return name;
}
/**
* Gets the password
*/
public String getPassword()
{
return password;
}
/*
* Saves user information to a text file
*/
public void saveUser()
{
File nameDir = new File("H:/SDI/MileStoneMyWorkSpace/MileStoneMyWorkSpace/users/" + name);
nameDir.mkdir(); //creates directory
File fileo = new File("H:/SDI/MileStoneMyWorkSpace/MileStoneMyWorkSpace/users/" + name + ".dat");
try
{
DataOutputStream ou = new DataOutputStream(new FileOutputStream(fileo));
ou.writeBytes(name + " , " + password);
ou.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
/**
* What is called after getting username and password for your account right
*/
public void login()
{
}
/**
* Reads the users account Information from the text file and matches it to user input to see if it is correct
*/
public void loadUser()
{
BufferedReader reader = null;
try{
reader = new BufferedReader(
new FileReader("H:\\SDI\\MileStoneMyWorkSpace\\MileStoneMyWorkSpace\\users\\" + name + ".dat"));
System.out.println("Results...");
String line;
line = reader.readLine();
while(line != null) {
System.out.println(line);
if(line.equals(name + " , " + password))
{
System.out.println("Right u aree ");
access = true;
}
else
{
System.out.println("WRONGGG");
access = false;
}
line = reader.readLine();
}
System.out.println();
}
catch(FileNotFoundException e){
System.out.println("Unable to find the file " + name + ".dat" );
}
catch(IOException e) {
System.out.println("Error found reading the file: " + name + ".dat" );
}
finally{
if(reader != null) {
//Catch any exception but nothing can be done about it.
try{
reader.close();
}
catch(IOException e) {
System.out.println("Error on closing: " + name + ".dat");
}
}
}
}
/**
* Gets user access
* If user input it's correct password and username it has access
* @return boolean
*/
public boolean getAccess()
{
return access;
}
}
[/code]
Basically there is a Jlist in my GUI and I want it to display the files stored in my user folder.
But for some reason it doesnt work the Jlist say that there is Null file.
[code = java]
package milestonemyworkspace;
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;
import java.lang.reflect.Array;
/**
* Handles the account details and login access.
*
* @author Abimar Skrubel
* @version 1.0
*/
public class User
{
private String name; //Username
private String password; //The Special Picture
private boolean access;
public User()
{
}
/**
* Sets the username
*/
public void setName(String name)
{
this.name = name;
}
/**
* Sets the password
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* Gets the username
*/
public String getName()
{
return name;
}
/**
* Gets the password
*/
public String getPassword()
{
return password;
}
/*
* Saves user information to a text file
*/
public void saveUser()
{
File nameDir = new File("H:/SDI/MileStoneMyWorkSpace/MileStoneMyWorkSpace/users/" + name);
nameDir.mkdir(); //creates directory
File fileo = new File("H:/SDI/MileStoneMyWorkSpace/MileStoneMyWorkSpace/users/" + name + ".dat");
try
{
DataOutputStream ou = new DataOutputStream(new FileOutputStream(fileo));
ou.writeBytes(name + " , " + password);
ou.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
/**
* What is called after getting username and password for your account right
*/
public void login()
{
}
/**
* Reads the users account Information from the text file and matches it to user input to see if it is correct
*/
public void loadUser()
{
BufferedReader reader = null;
try{
reader = new BufferedReader(
new FileReader("H:\\SDI\\MileStoneMyWorkSpace\\MileStoneMyWorkSpace\\users\\" + name + ".dat"));
System.out.println("Results...");
String line;
line = reader.readLine();
while(line != null) {
System.out.println(line);
if(line.equals(name + " , " + password))
{
System.out.println("Right u aree ");
access = true;
}
else
{
System.out.println("WRONGGG");
access = false;
}
line = reader.readLine();
}
System.out.println();
}
catch(FileNotFoundException e){
System.out.println("Unable to find the file " + name + ".dat" );
}
catch(IOException e) {
System.out.println("Error found reading the file: " + name + ".dat" );
}
finally{
if(reader != null) {
//Catch any exception but nothing can be done about it.
try{
reader.close();
}
catch(IOException e) {
System.out.println("Error on closing: " + name + ".dat");
}
}
}
}
/**
* Gets user access
* If user input it's correct password and username it has access
* @return boolean
*/
public boolean getAccess()
{
return access;
}
}
package milestonemyworkspace;
import java.util.*;
import java.io.*;
/**
* Lists files in fileList
*
* @author Abimar Skrubel
* @version 1.0
*/
public class ListFiles
{
private ArrayList files;
private User user;
public ListFiles()
{
files = new ArrayList();
User user = new User();
}
//Write files to array list object
public void writeFiles()
{
user.getName();
try{
File fileo = new File(
"H:/SDI/MileStoneMyWorkSpace/MileStoneMyWorkSpace/users/" + user.getName() +
"/fileList.dat");
DataOutputStream ou = new DataOutputStream(new FileOutputStream(fileo));
ou.writeBytes(user.getName());
ou.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
//read files to put in J list
public void readFiles()
{
BufferedReader reader = null;
try{
reader = new BufferedReader(
new FileReader("H:\\SDI\\MileStoneMyWorkSpace\\MileStoneMyWorkSpace\\users\\" + user.getName() + "fileList.dat"));
System.out.println("Results...");
String line;
line = reader.readLine();
while(line != null) {
System.out.println(line);
line = reader.readLine();
}
System.out.println();
}
catch(FileNotFoundException e){
System.out.println("Unable to find the file " + user.getName() + ".dat" );
}
catch(IOException e) {
System.out.println("Error found reading the file: " + user.getName() + ".dat" );
}
finally{
if(reader != null) {
//Catch any exception but nothing can be done about it.
try{
reader.close();
}
catch(IOException e) {
System.out.println("Error on closing: " + user.getName() + ".dat");
}
}
}
}
public Object getFiles()
{
return files;
}
}
package milestonemyworkspace;
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;
import java.lang.reflect.Array;
/**
* Handles the account details and login access.
*
* @author Abimar Skrubel
* @version 1.0
*/
public class User
{
private String name; //Username
private String password; //The Special Picture
private boolean access;
public User()
{
}
/**
* Sets the username
*/
public void setName(String name)
{
this.name = name;
}
/**
* Sets the password
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* Gets the username
*/
public String getName()
{
return name;
}
/**
* Gets the password
*/
public String getPassword()
{
return password;
}
/*
* Saves user information to a text file
*/
public void saveUser()
{
File nameDir = new File("H:/SDI/MileStoneMyWorkSpace/MileStoneMyWorkSpace/users/" + name);
nameDir.mkdir(); //creates directory
File fileo = new File("H:/SDI/MileStoneMyWorkSpace/MileStoneMyWorkSpace/users/" + name + ".dat");
try
{
DataOutputStream ou = new DataOutputStream(new FileOutputStream(fileo));
ou.writeBytes(name + " , " + password);
ou.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
/**
* What is called after getting username and password for your account right
*/
public void login()
{
}
/**
* Reads the users account Information from the text file and matches it to user input to see if it is correct
*/
public void loadUser()
{
BufferedReader reader = null;
try{
reader = new BufferedReader(
new FileReader("H:\\SDI\\MileStoneMyWorkSpace\\MileStoneMyWorkSpace\\users\\" + name + ".dat"));
System.out.println("Results...");
String line;
line = reader.readLine();
while(line != null) {
System.out.println(line);
if(line.equals(name + " , " + password))
{
System.out.println("Right u aree ");
access = true;
}
else
{
System.out.println("WRONGGG");
access = false;
}
line = reader.readLine();
}
System.out.println();
}
catch(FileNotFoundException e){
System.out.println("Unable to find the file " + name + ".dat" );
}
catch(IOException e) {
System.out.println("Error found reading the file: " + name + ".dat" );
}
finally{
if(reader != null) {
//Catch any exception but nothing can be done about it.
try{
reader.close();
}
catch(IOException e) {
System.out.println("Error on closing: " + name + ".dat");
}
}
}
}
/**
* Gets user access
* If user input it's correct password and username it has access
* @return boolean
*/
public boolean getAccess()
{
return access;
}
}
[/code]
Last edited by eeeman; Apr 5th, 2007 at 9:39 am.
![]() |
Similar Threads
- Please help me in connecting JSP to MySql (JSP)
- Libraries (C++)
- Making MP3 CD (Windows NT / 2000 / XP)
- View the Ratings of Web Hosts First (Networking Hardware Configuration)
- string stream (C++)
- Virus Of Death - Help Needed! (Viruses, Spyware and other Nasties)
- Former Abyss newbie ; folder help (Linux Servers and Apache)
- Yet another About;Blank homepage problem (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: Error running Java
- Next Thread: convert infex to prefix
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online pearl printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor





