Lowercase problems...

zotdog69
zotdog69 used Ask the Experts™
on
I'm working on a program for changing uppercase letters to lowercase. This is what I have so far:
class lowercase
{
Set objFileSystem = CreateObject("Scripting.fileSystemObject");
Set objOriginalFile = objFileSystem.OpenTextFile(OriginalFile,1,True)
Reader = objOriginalFile.ReadAll;
objOreginalFile.Close;

LowerCaseReader = LCase (Reader);
Set objEndFile = objFileSystem.OpenTextFile(EndFile,2,True);
objEndFile.Write LowerCaseReader;
objEndFile.Close;
Set objEndFile = Nothing;
Set objOriginalFile = Nothing;
Set objFileSystem = Nothing;
}
And these are the errors I'm getting:lowercase.java:6: <identifier> expected
Reader = objOriginalFile.ReadAll;
      ^
lowercase.java:7: <identifier> expected
objOreginalFile.Close;// read from the file then close the file
                     ^
lowercase.java:9: <identifier> expected
LowerCaseReader = LCase (Reader);//converts all to lower Case
               ^
lowercase.java:12: <identifier> expected
objEndFile.Close;//write all to the end file
                ^
4 errors
Along with the obvious errors up top, I have researched the answers on how to create a file .TXT, but am very unsure of how to do it. Keep in mind, I'm running Coderunner (MAC) and don't know if it can import/export to a file.
Thanks, this is the last program I HAVE to do, so now I can start doing programs I want to do!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
The code you posted seems to be VBScript not Java.

Author

Commented:
you're right, copied wrong one. Coderunner all look the same.
public void toLowerCase(String inFile, String outFile) throws IOException {
            BufferedReader in = new BufferedReader(new InputStreamReader(newFileInputStream(inFile)));
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
            
            String line;
            while((line = in.readLine()) != null)
                  out.write(line.toLowerCase() + "\n");
            
            in.close();
            out.close();
      }
Awarded 2011
Awarded 2011

Commented:

java has to have parenteses after mathod name:
objEndFile.Close; - this cannot be java method

 you also need to have some method which would contain
executable code, not just class
Awarded 2011
Awarded 2011

Commented:
So what about this new java code - does it generate errors?

Author

Commented:
class lowercase{
public void toLowerCase(String inFile, String outFile) throws IOException {
            BufferedReader in = new BufferedReader(new InputStreamReader(newFileInputStream(inFile)));
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
           
            String line;
            while((line = in.readLine()) != null)
                  out.write(line.toLowerCase() + "\n");
           
            in.close();
            out.close();
}
Untitled.java:11: reached end of file while parsing
            out.close();}
                         ^

Author

Commented:
Sorry about the confusion, its been a long day.
It says parsing error, but its ended with }.

Also, is there possibly a Dummies version of how to do the .TXT input and export?
Awarded 2011
Awarded 2011

Commented:
You don't have enough braces - class{ is not closed - in the snippet in the last posting
Top Expert 2011

Commented:
The following code compiles, and it should work though I have not tested.  Btw, by convention class names in Java use camel casing, so you class name should be Lowercase.

import java.io.*;

public class Lowercase{
    public void toLowerCase(String inFile, String outFile) throws IOException {
            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile)));
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));

            String line;
            while((line = in.readLine()) != null)
                  out.write(line.toLowerCase() + "\n");

            in.close();
            out.close();
    }
}

Open in new window


I hope this helps.
Awarded 2011
Awarded 2011

Commented:
You coode seems reasonable

import java.io.*;
public class LowerCase{
public static  void toLowerCase(String inFile, String outFile) throws IOException {
                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile)));
                BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
            
                String line;
                while((line = in.readLine()) != null)
                      out.write(line.toLowerCase() + "\n");
            
                in.close();
                out.close();
    }
    
    
	public static void main(String[] args) {
        
        try{
        toLowerCase("input.txt", "output.txt");
        }catch(Exception ex){
            
           ex.printStackTrace();
        }
	
}
}

Open in new window

Author

Commented:
you were right, closed it, and this is it:
class lowercase{
      
}
public void toLowerCase(String inFile, String outFile) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(newFileInputStream(inFile)));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
String line;
while((line = in.readLine()) != null)
out.write(line.toLowerCase() + "\n");
in.close();
out.close();
}

And now I have these:
lowercase.java:4: class, interface, or enum expected
public void toLowerCase(String inFile, String outFile) throws IOException {
       ^
lowercase.java:6: class, interface, or enum expected
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
^
lowercase.java:7: class, interface, or enum expected
String line;
^
lowercase.java:8: class, interface, or enum expected
while((line = in.readLine()) != null)
^
lowercase.java:10: class, interface, or enum expected
in.close();
^
lowercase.java:11: class, interface, or enum expected
out.close();
^
lowercase.java:12: class, interface, or enum expected
}
^
7 errors

Seems to be getting worse. What does the error code mean "class, interface, or enum expected" Maybe we could start there?
Awarded 2011
Awarded 2011

Commented:
You have closeing brace on the second line  - remove it
Awarded 2011
Awarded 2011

Commented:
This code copiles and executes - see input output below;

import java.io.*;
public class LowerCase{
public static  void toLowerCase(String inFile, String outFile) throws IOException {
                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile)));
                BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));

                String line;
                while((line = in.readLine()) != null)
                      out.write(line.toLowerCase() + "\n");

                in.close();
                out.close();
    }


	public static void main(String[] args) {

        try{
        toLowerCase("input.txt", "output.txt");
        }catch(Exception ex){

           ex.printStackTrace();
        }

}
}

Open in new window


input.txt:
[u][/u]
ASDSGGFhjhjh

Open in new window


output.txt:
asdsggfhjhjh

Open in new window

Awarded 2011
Awarded 2011

Commented:
Sorry input.txt above should be:

ASDSGGFhjhjh

Open in new window


Extar symbols came whiole pasting
Awarded 2011
Awarded 2011

Commented:
File input.txt should be in the default directory where you are executing your program
or in the project directpry for IDE

Author

Commented:
Got it, I looked at yours, and at least I was reasonably close.
Any assistance on the .txt part. Somehow, again Coderunner, I'm supposed to open a TXT with this, then creat another TXT for the outcome.
Awarded 2011
Awarded 2011

Commented:
In you code this should compile - I commented out offending closing brace:

class lowercase{
      
//}
public void toLowerCase(String inFile, String outFile) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(newFileInputStream(inFile)));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
String line;
while((line = in.readLine()) != null)
out.write(line.toLowerCase() + "\n");
in.close();
out.close();
} 

Open in new window

Awarded 2011
Awarded 2011

Commented:
No sorry , stil one more brace needed:

class lowercase{
      
//}
public void toLowerCase(String inFile, String outFile) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(newFileInputStream(inFile)));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
String line;
while((line = in.readLine()) != null)
out.write(line.toLowerCase() + "\n");
in.close();
out.close();
} 
}

Open in new window

Awarded 2011
Awarded 2011

Commented:
But in order to execute you also need method main() from which to start execution, so use my code above.
Awarded 2011
Awarded 2011

Commented:

>I'm supposed to open a TXT with this, then creat another TXT for the outcome.

That is exactly what my code above does ID:36319452

It opens input.txt and write to output.txt

Author

Commented:
I'm supposed to create my own file to test the program. So, how would you get this program to open a TXT file, check it, change it, and create a new file? If xxxxxx452 does this, how?

Author

Commented:
And, since I;m using Coderunner, not JDK, can this do what I'm asking?
Awarded 2011
Awarded 2011

Commented:

This one does what you want:

import java.io.*;
public class LowerCase{
public static  void toLowerCase(String inFile, String outFile) throws IOException {

                  BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(inFile)));
           out.write("ASDFGBHJkling");
               out.close();


                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile)));
                 out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));

                String line;
                while((line = in.readLine()) != null)
                      out.write(line.toLowerCase() + "\n");

                in.close();
                out.close();
    }


	public static void main(String[] args) {

        try{
        toLowerCase("input.txt", "output.txt");
        }catch(Exception ex){

           ex.printStackTrace();
        }

}
}

Open in new window

Awarded 2011
Awarded 2011

Commented:

Java should be the same no matter where - this should work everywhere

Author

Commented:
I need to read a file and convert all uppercase to lowercase.

I/O program that reads an input file, converts all the uppercase characters into lowercase without changing any other characters, and writes the characters to an output file.
Awarded 2011
Awarded 2011
Commented:
This is what the code above does.

It also first creates the file as you wanted and then closes it and then opens reads an rewrites it to output.txt - all what you wanted
Awarded 2011
Awarded 2011

Commented:
It first creates and writes string "ASDFGBHJkling" into file input.txt
Then it closes this file, then opens it again, then transfers all upper case to lower case
and write the result to file output.txt

I guess, that is what you described you need?

Author

Commented:
I guess I wasn't understanding the original question...I'll submit it and reply back as to the response.

Thank you for your patience!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial