Re: Help needed with code
Quote:
illegal escape character
the backslash \ (called the escape character) is a special character for the compiler. It allows you to tell the compiler to ignore the ordinary meaning of the character that follows it. For example if you want a " in a String you precede it with the \ : "A dbl quote: \" "
To use the \ in a String you must "escape" by preceding it with another \ for example \\
The first \ tells the compiler to take the second \ as an ordinary character
There are only a few characters that can be "escaped": n r " ' \ etc
Re: Help needed with code
The 'backslash' or 'escape' character is used in Java Strings to include a character that might otherwise have some special meaning. For example if you wanted a String that was just a single quote character you would code "\"" . See the bit on 'escape characters' at Characters (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
The compiler is complaining that \A is not on its list of known escapes. You could try doubling-up those backslashes in your Windows-style file paths, reading them from a Preferences object (so they're stored un-escaped elsewhere) or you could build your File objects a directory at a time using File root = new File(/* appropriate root - see File.listRoots() */; File fAppDir = new File(root, "AppData");
For portable Java code, try to avoid hard-coding any OS-specific Strings (like Windows file paths) in your apps.
Re: Help needed with code
Quote:
Originally Posted by
Norm
the backslash \ (called the escape character) is a special character for the compiler. It allows you to tell the compiler to ignore the ordinary meaning of the character that follows it. For example if you want a " in a String you precede it with the \ : "A dbl quote: \" "
To use the \ in a String you must "escape" by preceding it with another \ for example \\
The first \ tells the compiler to take the second \ as an ordinary character
There are only a few characters that can be "escaped": n r " ' \ etc
Quote:
Originally Posted by
Sean4u
The 'backslash' or 'escape' character is used in Java Strings to include a character that might otherwise have some special meaning. For example if you wanted a String that was just a single quote character you would code "\"" . See the bit on 'escape characters' at
Characters (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
The compiler is complaining that \A is not on its list of known escapes. You could try doubling-up those backslashes in your Windows-style file paths, reading them from a Preferences object (so they're stored un-escaped elsewhere) or you could build your File objects a directory at a time using File root = new File(/* appropriate root - see File.listRoots() */; File fAppDir = new File(root, "AppData");
Thanks guys, never knew that ( I guess thats what happens when your new (going to take java next year at com. college)) It got rid of those errors, but came back with these
Code :
Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Users\Owner>javac C:\Users\Owner\Desktop\Replacer.java
C:\Users\Owner\Desktop\Replacer.java:8: cannot find symbol
symbol : class IOException
location: class Replacer
public static void main(String[] args) throws IOException
^
C:\Users\Owner\Desktop\Replacer.java:13: cannot find symbol
symbol : class File
location: class Replacer
File inputFile= new File("\\AppData\\Roaming\\.minecraft\\bin\\minecraft.j
ar\\title\\splashes.txt");
^
C:\Users\Owner\Desktop\Replacer.java:13: cannot find symbol
symbol : class File
location: class Replacer
File inputFile= new File("\\AppData\\Roaming\\.minecraft\\bin\\minecraft.j
ar\\title\\splashes.txt");
^
C:\Users\Owner\Desktop\Replacer.java:21: cannot find symbol
symbol : method change()
location: class java.lang.StringBuffer
aLine= new StringBuffer(aLine).change().toString();
^
4 errors
C:\Users\Owner>
Re: Help needed with code
Quote:
cannot find symbol
symbol : class IOException
You need to add an import statement for the IOException class and the File class
Quote:
cannot find symbol
symbol : method change()
Where is the method: change() defined? What class is it in? The compiler can't find it.
Re: Help needed with code
well my code is at my first post, method change() is line 20
Code :
aLine= new StringBuffer(aLine).change().toString();
Its in the same class... It might be a bad rootword I'm actually not entirely sure that should be there. I wanted to change so I put that, I know java has a keyword of Exchanger, but I was unsure what it exactly did, so yea.
The first error that your talking about (symbol: Class IOException) I'm not entirely sure what you mean, can you explain some more, like I said I'm quite new to the language of Java.
Re: Help needed with code
Look at the top of your source file. There are import statements there. The import statement is used by the compiler to find class definitions for classes that are in a package. You need to add an import statement for the package that contains the IOException class. Read the API doc for the IOException class to see what package it is in.
Code :
new StringBuffer(aLine).change().toString();
Why are you coding the call to the change() method here?
Quote:
Its in the same class...
What class is the change() method in?
Here is the link to the API docs:Java Platform SE 6
Re: Help needed with code
Quote:
Originally Posted by
Norm
Look at the top of your source file. There are import statements there. The import statement is used by the compiler to find class definitions for classes that are in a package. You need to add an import statement for the package that contains the IOException class. Read the API doc for the IOException class to see what package it is in.
Code :
new StringBuffer(aLine).change().toString();
Why are you coding the call to the change() method here?
What class is the change() method in?
Here is the link to the API docs:
Java Platform SE 6
Oh I see what you mean, It might not be in any code. I was just looking through other java code to see how everything worked, & thought it might work. I'm just trying to make something that replaces one file with one you create in the applet by typing in a new line.
Re: Help needed with code
Is your program working now?
Re: Help needed with code
Quote:
Originally Posted by
Norm
Is your program working now?
No, I'm still not sure whats wrong, or what to replace
Re: Help needed with code
Post your current error messages here.
Have you removed the line of code with the change() method call in it?
If not, why do you have that line of code in your program?
Re: Help needed with code
Quote:
Originally Posted by
Norm
Post your current error messages here.
Have you removed the line of code with the change() method call in it?
If not, why do you have that line of code in your program?
Well I haven't changed anything since last error... the reason that line is their is because I was looking at another person's code & saw what it did, so I copied that line but changed the rootword
Re: Help needed with code
If you remove that line, what happens?
Re: Help needed with code
Quote:
Originally Posted by
Norm
If you remove that line, what happens?
Code :
Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Users\Owner>javac C:\Users\Owner\Desktop\BATCH FILES\Replacer.java
javac: invalid flag: C:\Users\Owner\Desktop\BATCH
Usage: javac <options> <source files>
use -help for a list of possible options
C:\Users\Owner>javac C:\Users\Owner\Desktop\Replacer.java
C:\Users\Owner\Desktop\Replacer.java:8: cannot find symbol
symbol : class IOException
location: class Replacer
public static void main(String[] args) throws IOException
^
C:\Users\Owner\Desktop\Replacer.java:13: cannot find symbol
symbol : class File
location: class Replacer
File inputFile= new File("\\AppData\\Roaming\\.minecraft\\bin\\minecraft.j
ar\\title\\splashes.txt");
^
C:\Users\Owner\Desktop\Replacer.java:13: cannot find symbol
symbol : class File
location: class Replacer
File inputFile= new File("\\AppData\\Roaming\\.minecraft\\bin\\minecraft.j
ar\\title\\splashes.txt");
^
3 errors
C:\Users\Owner>
this
Re: Help needed with code
Quote:
Well I haven't changed anything
Have you read posts#5 & #7?
I guess there is nothing I can do if you don't want to make the recommended changes.
Re: Help needed with code
Quote:
Originally Posted by
Norm
Have you read posts#5 & #7?
I guess there is nothing I can do if you don't want to make the recommended changes.
yea, but I'm not entirly sure what class I should add
Re: Help needed with code
Read the API doc, find the class definitions that the compiler can not find. Get the package that those classes are in (its near the very top of the page for the class's doc, above the Class.... and below the horizontal line) and add an import statement for that package to your code.
For example, you code has this import statement:
import java.io.InputStream;
go read the API doc for the InputStream class and see where the package (java.io) is defined for that class. Then look at the API doc for the classes the compiler can't find and get the package there.
Re: Help needed with code
Quote:
Originally Posted by
Norm
Read the API doc, find the class definitions that the compiler can not find. Get the package that those classes are in (its near the very top of the page for the class's doc, above the Class.... and below the horizontal line) and add an import statement for that package to your code.
For example, you code has this import statement:
import java.io.InputStream;
go read the API doc for the InputStream class and see where the package (java.io) is defined for that class. Then look at the API doc for the classes the compiler can't find and get the package there.
I spent about two hours looking through it with no class that could change one file to another, should I keep looking?
Re: Help needed with code
Quote:
class that could change one file to another
What does that have to do with solving the compiler errors?
What do you mean by "change one file to another"?
Do you mean rename an existing file? See the File class.
Do you mean change the contents of a file? There are several classes you can use to write out to a file.
Re: Help needed with code
Quote:
Originally Posted by
Norm
What does that have to do with solving the compiler errors?
What do you mean by "change one file to another"?
Do you mean rename an existing file? See the File class.
Do you mean change the contents of a file? There are several classes you can use to write out to a file.
well thats why .change is on that line, it used to have .reverse, because I retrieved it from another code, after I got aggravated with mine... yes I'm trying to replace one file with another