The Artima Developer Community
Sponsored Link

Java Answers Forum
how can i write a text file and run the command on the text file?

3 replies on 1 page. Most recent reply: Mar 26, 2003 5:55 AM by Dhrubo

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Roger

Posts: 6
Nickname: lionheart
Registered: Mar, 2003

how can i write a text file and run the command on the text file? Posted: Mar 25, 2003 3:23 AM
Reply to this message Reply
Advertisement
Hello guys,
i am new to java programming and need some help from you all. i created a program to prompt the user for his name
and setName() using a Person class. when the program is close, the name i set is gone.Im wondering if i can save the name i set, and heard that i can write it to a text file and then run the command on the Text file using something call the BufferReader (dunno if it is spelled correctly) can anyone show me how can i do it .. Thank you!!


Dhrubo

Posts: 32
Nickname: dhrubo
Registered: Mar, 2003

Re: how can i write a text file and run the command on the text file? Posted: Mar 26, 2003 5:23 AM
Reply to this message Reply
import java.io.*;
import java.util.*;

class GenericTool {


public static void main(String[] args)
{

File flDirInput = new File("C:\\GMAC\\JSPs\\ACCOUNTING");

File[] flJspList = null;

if(flDirInput.isDirectory())
{
System.out.println(flDirInput+ " is a directory.");

flJspList = flDirInput.listFiles();
}
else
{
System.out.println(flDirInput+ " is a not a directory.");
System.exit(1);
}
System.out.println("\t Starting Test.........." );


int count=0;
int intTotFileCount = flJspList.length;

boolean blFlag = false;
try
{
String logFile = "C:\\GMAC\\Report.log";

FileWriter fw = new FileWriter(logFile);

BufferedWriter bw = new BufferedWriter(fw);

String strJspToTest = "";
for (int i=0; i< intTotFileCount ; i++)
{
strJspToTest = flJspList.toString();



if(strJspToTest.indexOf(".jsp") !=-1)
{
blFlag = GenerateReport(flJspList.toString());

if(blFlag==false)
{
bw.write("File : "+strJspToTest);
bw.newLine();
}

}
else
{
//bw.write("Not a JSP.Rejecting test.");
bw.newLine();
}

}//for

bw.close();
fw.close();
}//try
catch(Exception e)
{
System.out.println(e);
}
System.out.println("\t\t\t\tTest Over.........." );
System.out.println("\n\n\t\t\t\tView Log file for details." );
}

public static boolean GenerateReport(String strJspToTest)
{
boolean blFlag = false;
FileReader fr = null;
BufferedReader br = null;
try
{
fr = new FileReader(strJspToTest);

br = new BufferedReader(fr);

String s = "";

while((s = br.readLine()) != null)
{
if( s.toUpperCase().indexOf("BODY") ==-1)
{
//strMessage = "onLoad Attribute not found in body tag." ;

}else
{
System.out.println("INSIDE BODY TAG");
if(s.indexOf("onLoad") != -1)
{
System.out.println("INSIDE not onloAd");
blFlag = true;
break;
}
else
System.out.println(s+"\n");
}

}//while

br.close();
fr.close();

}//try
catch(Exception e)
{
System.out.println(e);


}//catch



return blFlag;
}

}

Roger

Posts: 6
Nickname: lionheart
Registered: Mar, 2003

Re: how can i write a text file and run the command on the text file? Posted: Mar 26, 2003 5:30 AM
Reply to this message Reply
Thanks for the HElp!! although i don't fully understand the code, i will try to figure out myself =)

Dhrubo

Posts: 32
Nickname: dhrubo
Registered: Mar, 2003

Re: how can i write a text file and run the command on the text file? Posted: Mar 26, 2003 5:55 AM
Reply to this message Reply
Friend this program gets the latest version of code from vss in a folder and then finds a certain attribute in the body tag .... at the same time it reports the log in a log file

Flat View: This topic has 3 replies on 1 page
Topic: java,jsp,ejb interview related questions Previous Topic   Next Topic Topic: large problem with int

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use