₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,330,989 members, 8,448,114 topics. Date: Sunday, 19 July 2026 at 07:03 PM

Toggle theme

I Am Stuck In My Project...i Need Help From A Good Java Programmer - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingI Am Stuck In My Project...i Need Help From A Good Java Programmer (1144 Views)

1 Reply

I Am Stuck In My Project...i Need Help From A Good Java Programmer by NigerianScholar(op): 10:49am On Oct 31, 2017
without boring you with the details..ill just say what i need to be done in my code. btw, i have imported the java io package
1. i need to be able to save the user input in a new file e.g txt file
2. i need to be able to save the user input in an existing file i.e to update
3. to list all the file names/directories in the folder.. to do it in cmd prompt you nav to the path and type dir
4. i need to be able to view a file specified by the user

Thank you for your help...feel free to mention anyone that may have relevant knowledge in this or give me the link to a java group chat
Re: I Am Stuck In My Project...i Need Help From A Good Java Programmer by seunthomas: 3:09pm On Oct 31, 2017


import java.io.*;
import java.util.*;

class Help{
private File file;

protected File createFile(String filename){
try{
file = new File(filename);

if (!file.exists()) {
file.createNewFile();
}


}
catch(Exception ex){
ex.printStackTrace();
}

return file;
}

public String readFile(String filename){
String output="";
try{
file = new File(filename);

FileReader fr = new FileReader(file.getAbsolutePath());
BufferedReader br = new BufferedReader(fr);

String data;

while ((data = br.readLine()) != null) {
output = output + data ;
}

}
catch(Exception ex){
ex.printStackTrace();
}
return output;
}

public void appendToFile(String filename,String data){

try
{
boolean append=true;
writeToFile(filename, data,append);
}
catch(Exception ex)
{
ex.printStackTrace();
}

}

//String filename
//String data to write
//boolean append or just write
public void writeToFile(String filename,String data,boolean append){
try
{
File f = createFile(filename);
FileWriter fwrite = new FileWriter(f.getAbsoluteFile(),append);
fwrite.write(data);
fwrite.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}

}

public File[] getDir(String dir){

File folder = new File(dir);
File[] files = folder.listFiles();
return files;
}



public static void main(String args[]){
String filename="test.txt";
Help hlp = new Help();
hlp.writeToFile(filename,"Hello World\n",false);
for(int i=0;i<=1000;i++){

hlp.appendToFile(filename,"Hello World "+String.valueOf(i)+"\n" ) ;

}
}



}



Re: I Am Stuck In My Project...i Need Help From A Good Java Programmer by NigerianScholar(op): 3:41am On Nov 01, 2017
seunthomas:


import java.io.*;
import java.util.*;

class Help{
private File file;

protected File createFile(String filename){
try{
file = new File(filename);

if (!file.exists()) {
file.createNewFile();
}


}
catch(Exception ex){
ex.printStackTrace();
}

return file;
}

public String readFile(String filename){
String output="";
try{
file = new File(filename);

FileReader fr = new FileReader(file.getAbsolutePath());
BufferedReader br = new BufferedReader(fr);

String data;

while ((data = br.readLine()) != null) {
output = output + data ;
}

}
catch(Exception ex){
ex.printStackTrace();
}
return output;
}

public void appendToFile(String filename,String data){

try
{
boolean append=true;
writeToFile(filename, data,append);
}
catch(Exception ex)
{
ex.printStackTrace();
}

}

//String filename
//String data to write
//boolean append or just write
public void writeToFile(String filename,String data,boolean append){
try
{
File f = createFile(filename);
FileWriter fwrite = new FileWriter(f.getAbsoluteFile(),append);
fwrite.write(data);
fwrite.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}

}

public File[] getDir(String dir){

File folder = new File(dir);
File[] files = folder.listFiles();
return files;
}



public static void main(String args[]){
String filename="test.txt";
Help hlp = new Help();
hlp.writeToFile(filename,"Hello World\n",false);
for(int i=0;i<=1000;i++){

hlp.appendToFile(filename,"Hello World "+String.valueOf(i)+"\n" ) ;

}
}



}



thank you i should get back to you as soon as i try it
1 Reply

A Website With All Algorithm Solutions (my Project)Hello, An Aspiring Java Programmer Here! Like-minded Friends Oya UniteJava Programmer Wanted234

Yeapyapp Is Offering Free Websites For Any 20 Lucky Entrepreneur This Christmas!Zuckerberg Deflects US Senators’ Facebook Questions, And Gets $3 BillionNairaland Has Finally Added SSL After All These Years