Question about Sun Java Programming Language (cdj-275)

1 Answer

I want to read text file which is located in c drive using java code can anybody help me out

Posted by on

Ad

1 Answer

  • Level 2:

    An expert who has achieved level 2 by getting 100 points

    MVP:

    An expert that gotĀ 5 achievements.

    Governor:

    An expert whose answer gotĀ voted for 20 times.

    Hot-Shot:

    An expert who has answered 20 questions.

  • Expert
  • 98 Answers

Import java.io.*;
import java.util.Scanner;

public final class ReadWithScanner { public static void main(String... aArgs) throws FileNotFoundException {
ReadWithScanner parser = new ReadWithScanner("C:\\Temp\\test.txt");
parser.processLineByLine();
log("Done.");
}

/**
* @param aFileName full name of an existing, readable file.
*/

public ReadWithScanner(String aFileName){
fFile = new File(aFileName);
}

/** Template method that calls {@link #processLine(String)}. */
public final void processLineByLine() throws FileNotFoundException {
Scanner scanner = new Scanner(fFile);
try {
//first use a Scanner to get each line
while ( scanner.hasNextLine() ){
processLine( scanner.nextLine() );
}
}
finally {
//ensure the underlying stream is always closed
scanner.close();
}
}

/**
* Overridable method for processing lines in different ways.
*
* <P>This simple default implementation expects simple name-value pairs, separated by an
* '=' sign. Examples of valid input :
* <tt>height = 167cm</tt>
* <tt>mass = 65kg</tt>
* <tt>disposition = "grumpy"</tt>
* <tt>this is the name = this is the value</tt>
*/

protected void processLine(String aLine){
//use a second Scanner to parse the content of each line
Scanner scanner = new Scanner(aLine);
scanner.useDelimiter("=");
if ( scanner.hasNext() ){
String name = scanner.next();
String value = scanner.next();
log("Name is : " + quote(name.trim()) + ", and Value is : " + quote(value.trim()) );
}
else {
log("Empty or invalid line. Unable to process.");
}
//(no need for finally here, since String is source)
scanner.close();
}

// PRIVATE //
private final File fFile;

private static void log(Object aObject){
System.out.println(String.valueOf(aObject));
}

private String quote(String aText){
String QUOTE = "'";
return QUOTE + aText + QUOTE;
}
}

Posted on Jul 26, 2009

Ad

1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert can help you resolve that issue over the phone in a minute or two.
Best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of.(from cars to computers, handyman, and even drones)
click here to download the app (for users in the US for now) and get all the help you need.
Goodluck!

Posted on Jan 02, 2017

Ad

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

2 Answers

Using java code to access a machine's c drive


u can do that using java s file hadnling mechanism.

Oct 30, 2009 | Sun Java Programming Language (cdj-275)

2 Answers

Hi tryed to download javameantime, error code 25099 connot unzipp core files, how do i corect the problem,


WORKAROUND

Step 1 : Completely delete content of the following directory: C:\Program Files\Java\jre6\ (or alternate directory if you chose a non-default install location)

Step 2 : If Step 1 has permission issues due to files being locked or in use, restart your system

Step 3 : Now, completely delete content of the following directory: C:\Program Files\Java\jre6\

Step 4 : Download and install Java.
  1. Go to Java.com
  2. Click on the Free Java Download button, and start the installation process.

Sep 17, 2009 | Microsoft Windows XP Professional With...

1 Answer

Anybody couldnt open and see my files.what should i do??


If you would like to hide or secure your files from prying eyes, there are plenty of java applications available to lock them. Lock It Down is one of them

Jun 25, 2009 | Sony Ericsson K770i Purple 3G Camera...

1 Answer

Need to convert text to xml


Follow This Information's To Convert Text To # XML file #

fed9c89.gif
7a4d3fc.gif

236d20b.gif

Apr 13, 2009 | Sun Java Programming Language (cdj-275)

1 Answer

I have a hand written documents which is scanned and stored in a pdf format. i want to write coding to read this pdf file and convert the scanned text into normal text. is it possible using java. please...


No and here's why... Java is a programming language; its purpose is to be used to create programs that do useful things, but it is not equipped to do the complex analyses required to convert images to text. What you need is an OCR "image to text" conversion software application. Java is not such an application; it is a programming language meant to be used by programmers in a "platform independent context" (usually the World Wide Web). I suggest searching Google for what you need using these keyword strings: OCR image-to-text software. OCR stands for Optical Character Recognition.

Note that performing OCR on handwritten text is particularly difficult because it is so non-uniform (irregular). Here is a link that may be helpful in your quest for what is on its face at least by the way you asked, a very difficult process: http://www.softpedia.com/get/Office-tools/Other-Office-Tools/OCR-Image-to-Text-Conversion-Tool.shtml.

As one of my best programming professors (who taught me Java) used to say, "Yes, anything is possible in creating a computer program, but only if you have enough what? Skills, money and time to get the job done! Don't forget: time is money, so you know, don't bite off more than you can chew."

Apr 11, 2009 | Sun Java Programming Language (cdj-275)

2 Answers

Rename a folder in c drive using java code


import java.io.*;

public class RenameFileOrDir{

public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter the file or directory
name which has to be Renamed : ");

String old_name = in.readLine();
File oldfile = new File(old_name);


if(!oldfile.exists())
{

System.out.println("File or directory does not exist.");

System.exit(0);

}

System.out.print("please enter the new file or directory name : ");

String new_name = in.readLine();

File newfile = new File(new_name);

System.out.println("Old File or directory name : "+ oldfile);
System.out.println("New File or directory name : "+ newfile);
boolean Rename = oldfile.renameTo(newfile);

if(!Rename)
{

System.out.println("File or directory does not rename successfully.");

System.exit(0);

}

else {

System.out.println("File or directory rename is successfully.");

}

}

}

Mar 30, 2009 | Sun Java Programming Language (cdj-275)

4 Answers

What is the difference between Java editor and Java software?


java editor is a text editor which probably understands java language synthax and can automatically call java to compile your code.
Java software is a program written in Java programming language which is interpreted/executed by JVM(JAva virtual machine) on a target computer.
Your question is a rough equivalent to : What is a difference between typewriter and a recipe book written in English language

Jan 21, 2009 | Microsoft Windows Vista Ultimate Edition

1 Answer

Cannot install/uninstall Java


hi,
It is not necessary to install java in order to use java.
Just download java highest version, copy and paste the java software in the system drive(eg C:,D:,....), Then set path the java file.
Example, if you have the java file in your C drive, do the following steps

1. Goto start->Run-> type command. Command prompt(black screen) will open.
2. if it shows as C:> follow the steps, else Goto step 6.
3. set path="c:\Java file name"
4. type javac
5.after typing if u find compiler then Java is installed in your system.
6. Example... if it shows as F:> and if u have saved your file in C:, do the following.
7. cd..
8. cd..
9. cd C
10 .then it appears as C:>, follow from the step 3.

thank you.

May 07, 2008 | ArcMedia JavaScript Source Code 3000 Pro...

8 Answers

How to install java application and games on J600


For installing games stored on youre phone ( .Jad ) try the java midlet install menu: code *#9998*5282# -> install MIDlet password: 235282

Then you can select a .Jad file (.Jar must be included) stored on youre phone Memory (Stored on MicroSD probable too, but i don`t have one yet)

after install apps/Games, they are in the: application -> Java world -> "My Games" folder (menu-3-4-My Games)


I have the E900XXFF2 Firmware, the password works fine on it. I think on other versions too, because the password was meant for Samsung D807.

enjoy the pass, if it works on youre firmware, but i think it will work :)

*#3243948# Digital Audio Interference Off

*#32436837# Digital Audio Interference On

*#1111# Software Version

*#2222# Hardware Version

*#1234# Firmware Version

*#92782# WAP User Agent

*#927827# WAP WAProfile

*#0228#/*#9998*228# Battery profile

* # 0842 # Vib test
* # 0746 # SSMS MEMORY
* # 0638 # SIM SIM network ID
* # 0778 # SST Sim service Table
* # 0289 # Buz test
* # 0782 # RTC (RealTimeClock) (# = Refresh)

* # 9998*228 # Battery Profile
* # 9998*842 # Vib test
* # 9998*746 # SSMS MEMORY
* # 9998*638 # SIM SIM network ID
* # 9998*778 # SST Sim service Table
* # 9998*289 # Buz test
* # 9998*782 # RTC (RealTimeClock) (# = Refresh)
* # 9998*968 # YAMAHA OF OK ONE
* # 9998*76 # Product NUMBER
* # 9998*377 # error memory
* # 9998*5646 # GPRS Logo

----------------------------------------------

Code, whose effect and/or function I exactly do not point

* # 9324 # monitor? (with the red key velassen)
* # 32436837 # DAI ON?
* # 22766 # Automatically Recive call?
* # 227633 # manual Recive call?

----------------------------------------------

!!! RESET code!!!
!!! these codes use only if you know which it does!!!
!!! Thus data in the Handy are deleted!!!

* 2767*3855 # FULL RESET
* 2767*2878 # CUST RESET
* 2767*927 # WAP RESET
* 2767*667 # MMS RESET
* 2767*36245 # email RESET

Aug 13, 2007 | Samsung SGH-E900 Cellular Phone

Not finding what you are looking for?
Computers & Internet Logo

297 people viewed this question

Ask a Question

Usually answered in minutes!

Top Sun Computers & Internet Experts

Les Dickinson
Les Dickinson

Level 3 Expert

18408 Answers

Cosma Papouis
Cosma Papouis

Level 3 Expert

409 Answers

Robin Hill
Robin Hill

Level 3 Expert

1263 Answers

Are you a Sun Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...