unexpected token / cannot resolve symbol error

V

vivienne wykes

I am writing a small class to read the file names from a folder and then
removes the extension.

ie Anderson.txt becomes Anderson.

I plan to then write the new file names to a db table.

I have an error here File dir = new File("C:\java_file_reader");
unexpected token...

Any ideas welcome ---Full code below.

Regards


import java.io.*;
public class AddWedding2
{
String i;
String filename;
public AddWedding2() { }
public static void main (String argv[])
{
File dir = new File("C:\java_file_reader");
String[] files = dir.list();
if (files == null)
{
// Either dir does not exist or is not a directory
}
else
{
for (int i=0; i<files.length; i++)
{
// Get filename of file or directory
String filename = files;
// Show the file names in stack trace
System.out.println("current text file is " + filename );


String no_extension;
//convert string array element into a char array
char [] charsfilename = filename.toCharArray();

int newlength = charsfilename.length -4;
no_extension = String.valueOf(charsfilename,0,newlength);
// Show the new file names in stack trace without extension
System.out.println("String no_extension " + no_extension );




}
}
}
}
 
C

Cid

I am writing a small class to read the file names from a folder and then
removes the extension.

ie Anderson.txt becomes Anderson.

I plan to then write the new file names to a db table.

I have an error here File dir = new File("C:\java_file_reader");
unexpected token...

Any ideas welcome ---Full code below.

It's probably due to the fact that you need to escape the \ character
in your path string. Presumably you're getting an error message like

test.java:[line#]: illegal escape character

Because \j isn't a valid escape sequence. You want
"c:\\java_file_reader".

You really need to post the _exact_ and complete text of your error
messages if you want help. I believe I recommended that to you on an
earlier occasion too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top