•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,420 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,623 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1926 | Replies: 0
![]() |
•
•
Join Date: Mar 2007
Posts: 27
Reputation:
Rep Power: 2
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Please help me in connecting JSP to MySql (JSP)
- Libraries (C++)
- Making MP3 CD (Windows NT / 2000 / XP / 2003)
- 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


Linear Mode