943,621 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4359
  • Java RSS
Apr 5th, 2007
0

Putting files in Jlist

Expand Post »
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]
Last edited by eeeman; Apr 5th, 2007 at 9:39 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
eeeman is offline Offline
27 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Error running Java
Next Thread in Java Forum Timeline: convert infex to prefix





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC