aspose file tools*
The moose likes Beginning Java and the fly likes Save file without unwanted extensions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Save file without unwanted extensions" Watch "Save file without unwanted extensions" New topic
Author

Save file without unwanted extensions

Chris Rothburn
Greenhorn

Joined: Dec 14, 2011
Posts: 15
Trying to follow "How to create your first Java program at JavaRanch"

I can't send MooseGreetings to the compiler, because I can't open a command prompt directed to the file. I think the issue is a hidden file extension on the cut and pasted program, which I tried to save as MooseGreetings.java

I copied it onto Microsoft Word, my text editor, and tried to save it as plain text, a Word document, and RTF- pretty much the only options I have.

Although the extentions are hidden, I believe the file is being saved as MooseGreetings.java.txt, MooseGreetings.java.doc, and MooseGreetings.java.rtf This is preventing me from opening a command prompt on the file.

I've spent a few hours trying to figure out how to eliminate these unwanted extensions, including Windows Help (useless), Beginning Java FAQ, searching this forum, etc., and finally just decided to ask.

Thanks in advance for your help!
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Avoid using Word. Use any simple text editor like TextPad.

In Notepad / TextPad -> Paste the code in the editor -> Click Save - and select "Save as Type->" as "All Files" and give the name of the class as "MooseGreetings.java".
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

I also suggest turning off the feature where Windows hides file extensions from you. That's an extremely unuseful feature for a programmer. (I would explain how but it's completely different for different versions of Windows.)
Chris Rothburn
Greenhorn

Joined: Dec 14, 2011
Posts: 15
John Jai wrote:Avoid using Word. Use any simple text editor like TextPad.

In Notepad / TextPad -> Paste the code in the editor -> Click Save - and select "Save as Type->" as "All Files" and give the name of the class as "MooseGreetings.java".


By switching to notepad, saving as "all files", and changing the encoding to "unicode" I was able to crate a file with just the .java extension (saving as ANSI created a .doc (Word) file). However, I still can't open a command prompt directed to the file- if i try to open a command prompt directed to the folder it is in, I get

The system cannot find the path specified.
C:\>

If I try to enter the suggested input "javac MooseGreetings.java" (without the quotation marks, I assumed) it says
'javac' is not recognized as an internal or external command, operable program, or batch file.

When I try to do the same for MooseGreetings.java, it does not give me the option of a command prompt- the same problem I had using Word.

However, now, when I try to open MooseGreetings.java, which is now shown as a JAVA file, I get the "Windows cannot open this file...Windows needs to know what program created it" error message, and if I ask it to look it up on the web it tells me it is a JAVA source file.

So I guess the question has become (am I allowed to ask a "new" question on the same thread?) why can't I open a command prompt on this JAVA file? (If I right-click a folder I am given the option of a command prompt- that took some doing in itself...)

Chris Rothburn
Greenhorn

Joined: Dec 14, 2011
Posts: 15
Went back, redid everything from square one, found that my environment variables had not been saved- still can't open a command prompt on the source document, but I was able to open one on the folder it was in, then specify the folder and document, which resulted in the following 53 error message which I will annoy everyone by posting in full- was this because it was in unicode rather than ANSI? And if so, how can I save an ANSI document on notepad without the .doc extension? (Back to my original question...)


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

Yup.

When I do "Save As" in Notepad I see a button at the bottom of the Save dialog named "Encoding" whose values include ANSI and Unicode and so on. ("Unicode" is Microsoft's pet name for UTF-16, by the way, which is what you showed in your post.) Mine defaults to ANSI (which is Microsoft's pet name for whatever ASCII variant is used on your machine, which is locale-dependent, and it's CP1252 for English-speaking locales).

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
Get a decent text editor, eg jEdit, NotePad2, NotePad++, and set up options including
  • Syntax highlighting
  • Bracket Matching
  • Automatic indentation
  • Automatic conversion of tabs [to 4 spaces]
  • ... and you will find it makes life much easier for you. MS Notepad is a bit too basic to be any good for programming.
    Chris Rothburn
    Greenhorn

    Joined: Dec 14, 2011
    Posts: 15
    "Get a decent text editor, eg jEdit, NotePad2, NotePad++,..."


    Yes, I am beginning to come to the realization that a different text editor is the solution.

    Considering the hours I have wasted trying to use Word and Notepad, I wish I had just gone straight to getting something different, before my frustration level reached its current point!

    Why was it so much easier to compile FORTRAN programs back in 1976, my most recent programming experience? It seems like I am fighting Windows every step of the way, trying to get the processor to do what I want. I would have thought that things would have gotten easier. Even punch cards didn't give me this kind of frustration!

    Anyway, thank you, everyone, for your help!
    Matthew Brown
    Bartender

    Joined: Apr 06, 2010
    Posts: 4387
        
        8

    Chris Rothburn wrote:Why was it so much easier to compile FORTRAN programs back in 1976, my most recent programming experience? It seems like I am fighting Windows every step of the way, trying

    Well, you'd have had the same problem writing FORTRAN if you were using a word processor instead of a text editor.
    Winston Gutkowski
    Bartender

    Joined: Mar 17, 2011
    Posts: 7779
        
      21

    Chris Rothburn wrote:Why was it so much easier to compile FORTRAN programs back in 1976, my most recent programming experience?

    Because the machine you ran it on was designed specifically for it (and possibly COBOL and a few other languages of the time).

    It seems like I am fighting Windows every step of the way, trying to get the processor to do what I want. I would have thought that things would have gotten easier. Even punch cards didn't give me this kind of frustration!

    That's probably because Windows was never designed for techies; it was designed for "users" - specifically, ones with little or no computer background.
    If you want something more like your 1976 experience, try Linux (or Unix). The terminal shells provide you with a command-driven environment that is probably closer to what you're used to; however, they also require you to be much more precise. The OS itself is also superior to Windows in almost every conceivable way outside the "desktop/GUI experience" - and with distributions like Linux Mint, it's almost caught up even there.

    Winston


    Isn't it funny how there's always time and money enough to do it WRONG?
    Articles by Winston can be found here
    Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18564
        
        8

    Chris Rothburn wrote:Why was it so much easier to compile FORTRAN programs back in 1976, my most recent programming experience?


    Everything is more complex than it was in 1976 (I was programming then and I can confirm that). It looks to me like our whole civilization is groaning under the weight of all that complexity... but that's a different thread.
    Chris Rothburn
    Greenhorn

    Joined: Dec 14, 2011
    Posts: 15
    John Jai wrote:Avoid using Word. Use any simple text editor like TextPad.

    In Notepad / TextPad -> Paste the code in the editor -> Click Save - and select "Save as Type->" as "All Files" and give the name of the class as "MooseGreetings.java".


    I'm going to have to admit to being an idiot here...

    In the end, John Jai's advice proved to be correct. In notepad, saving as type- all files does indeed leave only the file extension you choose- in this case, .java

    It turned out my real problem, after I had switched to notepad, was only being able to open a command prompt onto a folder, not a file. At that point I was incorrectly formatting my file path. I just needed to read a little bit further to figure out where I had gone wrong.

    Just as a reference for other newbies who may experience the same frustration, the output of the command format that worked was:



    And while I read somewhere that blank space is generally ignored in Java, the spaces here all proved essential.

    Who would have thought that I could be so happy to get my screen to read "mooooooooooo" after only six hours of effort?

    Thanks again for the help, and I apologize that my ignorance cause me to offer so many red herrings...

    (Edit- By the way, the reason the JAVA_HOME and PATH enviromment variables were not saved proved to be because when it said, in "How to Create Your First Java Program at JavaRanch", under Windows XP, Item 8, "Click OK and close all remaining windows" I clicked OK in THAT window and closed the remaining windows using the typical "x" in the upper right corner. What was really needed was to click OK in ALL of the windows, thereby closing them. May I suggest an edit?)
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38765
        
      23
    Who told you whitespace is generally ignored? I don’t that that is correct. Whitespace may be necessary for separating tokens; the only place whitespace can be ignored is between operators (or separators) and operands eg i + j and i+j.
    Chris Rothburn
    Greenhorn

    Joined: Dec 14, 2011
    Posts: 15
    "Who told you whitespace is generally ignored?"

    Chapter one, page ten of "Head First Java", 2nd edition, under "Syntax Fun":

    "Most white space doesn't matter."

    I seem to have mis-interpreted that statement...
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19693
        
      20

    Most, not all. For example, there definitely needs to be whitespace between a variable type and name when you declare it.


    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
    How To Ask Questions How To Answer Questions
    John Simer
    Greenhorn

    Joined: Dec 19, 2011
    Posts: 16
    i hit this problem and you just have to save it with quotes

    i.e.

    instead of saving it as

    HelloWorldApp.java
    >which makes it "HelloWorldApp.java.txt"

    save it as

    "HelloWorldApp.java"
    >which saves it as "HelloWorldApp.java"

    Also make sure that when you click Save As, you choose "All Files" and not just ".txt" or ".rtf"

    ----------------------------EDIT--------------------------------------------
    my bad, John Jai already helped you.
    Chris Rothburn
    Greenhorn

    Joined: Dec 14, 2011
    Posts: 15
    John Simer.

    Any effort to help is appreciated!

    I'll try saving with quotes and see if that resolves the problem in some text editors when simply saving as "All Files" is insufficent or not an option.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38765
        
      23
    Stop using NotePad.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61196
        
      66

    Campbell Ritchie wrote:Stop using NotePad.

    Quoted for emphasis.

    Would you use a pair of scissors to chop carrots? Using the wrong tool for the job guarantees failure.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Chris Rothburn
    Greenhorn

    Joined: Dec 14, 2011
    Posts: 15
    Well, when the law tells you something, it's best to listen. And when a Sheriff and a Marshal both say the same thing, you'd better do it right quick.

    So, I ran to Google after reading these posts and got me a shiny new jEdit.

    Then struggled with the same command pathways I had trouble with before.

    Turns out, you can't (or at least I can't, using Windows XP Professional) direct a command prompt to a folder with a two part name, such as "source files". Once I changed the folder name to "sourcefiles", all my problems disappeared. Just for the benefit of all those other newbies out there...
    John Simer
    Greenhorn

    Joined: Dec 19, 2011
    Posts: 16
    In programming just avoid spaces period, i guess. Do "source_files" instead
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Save file without unwanted extensions