Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Help writing to a text file on a website!

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help writing to a text file on a website!

    Okay i have this website, (Project Quattro - Home), and i have uploaded a file to it (http://www.projectquattro.webs.com/java/javaarray.txt). i have entered some text into it and i can read that text perfectly but i'm having problems trying to write to it! here is what i have:

    package Alpha_1;
    import java.io.*;
    import java.net.*;
     
    /**
     *
     * @author Ollie
     */
    public class NewEmpty {
        NewEmpty(){
            String nextLine;
            URL url = null;
            URLConnection urlConn = null;
            InputStreamReader  inStream = null;
            BufferedReader buff = null;
            OutputStreamWriter out = null;
     
            try{
                url  = new URL("http://projectquattro.webs.com/java/javaarray.txt");  
                       //have tryed: http://projectquattro.webs.com:80/java/javaarray.txt
                urlConn = url.openConnection();
                urlConn.setDoOutput(true);
                urlConn.setAllowUserInteraction(true);
                urlConn.connect();
     
                out = new OutputStreamWriter(urlConn.getOutputStream());
                out.write("Hello Ollie");
                out.close();
     
            }catch(MalformedURLException e){
                System.out.println("Please check the URL:" + e.getMessage());
            }catch(IOException ex){
                System.out.println("Can't write to the Internet: " + ex.getMessage());
            }
     
            //i read from the file here but it just show what is originally there not what i have tried to write to it!
     
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,618
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Help writing to a text file on a website!

    'm having problems trying to write to it!
    Where does the code execute that is supposed to write to the file on the server? I would think that to write a file on the server, there must be code executed on the server to do the writing.
    Your code appears to write a String to the server from a client.
    What is the server supposed to do when it receives the String?

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help writing to a text file on a website!

    i haven't a clue tbh! i dont really know what im doing here, all i know is what i want to happen and that google hasnt helped me! also i dont know how much control i have over the server because its just a free .webs page!

  4. #4
    Member
    Join Date
    May 2010
    Posts
    38
    Thanks
    1
    Thanked 8 Times in 7 Posts

    Default Re: Help writing to a text file on a website!

    Umm... no, you can't do that from a client. If that were true, people could overwrite ANYTHING on a webserver and nobody would care.

    To accomplish what your trying to do, you going to do something unfortuanatly more complicated.
    1) Use a database. I would highly recommend JPersist
    2) Have a middleman on the server (written in PHP or some other server side language) that would write what you tell it to onto the server
    3) Store this file somewhere else

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,618
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Help writing to a text file on a website!

    he server because its just a free .webs page
    Can you read the FAQ or doc for the website to see how you can send it files?
    Some sites have a FTP interface that you can use to send files to a server.

    Think what the mess would be if it were as easy as you are trying to do.

  6. #6
    Junior Member
    Join Date
    Mar 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help writing to a text file on a website!

    yer i guess i was a bit naive thinking that! :/
    you see its not just me who will be using this so need something on the web!
    yess webs does have an ftp interface but you need a premium account for that!

    so my next question is does anyone know a free web hosting site with ftp access?

  7. #7
    Junior Member
    Join Date
    Mar 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help writing to a text file on a website!

    i've just seen this: FileZilla - The free FTP solution what that be a good substitute if i don't upgrade with webs?

    how easy will it be to write a java program to read/write files to it?

    thanks for all your help so fare!

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,618
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Help writing to a text file on a website!

    easy will it be to write a java program to read/write files
    It's not too hard to write your own FTP program in java. Find the RFC(request for comments - an old term) that defines the FTP protocol and code to its specifications.
    Use Google to find the RFC doc. It's quite old.

  9. #9
    Member
    Join Date
    May 2010
    Posts
    38
    Thanks
    1
    Thanked 8 Times in 7 Posts

    Default Re: Help writing to a text file on a website!

    Quote Originally Posted by straw View Post
    i've just seen this: FileZilla - The free FTP solution what that be a good substitute if i don't upgrade with webs?

    how easy will it be to write a java program to read/write files to it?

    thanks for all your help so fare!
    FileZilla is not a Java library, and therfor can't be used unless you really really want to use JNI.

    5 second's of googleing brought me to this benchmark: Update: Java FTP libraries benchmarked - JavaWorld

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,618
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Help writing to a text file on a website!

    If you're going to write a program to use FTP to upload the files, you should first understand the FTP protocol.
    The RFC for FTP gives all that there is, but its a bit detailed.
    You should get an account on a site that uses FTP and do a interaction manually with the site to get familiar with how it works.

  11. #11
    Junior Member
    Join Date
    Sep 2011
    Posts
    24
    My Mood
    Mellow
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help writing to a text file on a website!

    Before you get too far, you are going to need to change your web host. No matter what FTP client you use, you would still need to have an FTP account on the server, which is a paid-only feature on WEBS. I would recommend sites like 000webhost, byethost (spelling intentional), or 99k.org. For a more professional-looking domain name, try using co.cc to register a free domain and then update your nameservers.

Similar Threads

  1. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM
  2. [SOLVED] Writing " to a File
    By Sai in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 29th, 2010, 05:21 AM
  3. [SOLVED] Writing integers to a file
    By dubois.ford in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 15th, 2010, 06:18 PM
  4. Reading and Writing Text Files
    By kappasig84 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 1st, 2010, 06:16 PM
  5. Writing Output To New File
    By Scottj996 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: January 6th, 2010, 06:25 PM