Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:30:41+00:00 2026-06-13T00:30:41+00:00

Hi i am storing longitude and latitude values in textfile and saving them in

  • 0

Hi i am storing longitude and latitude values in textfile and saving them in my sdcard.now i want to save this data to webserver(java) textfile.please tell me how to create a textfile in server and also how to post data to that file.here is my code.

public class MainActivity extends Activity implements LocationListener{

private final static String STORETEXT="storetext.txt";


LocationManager locationManager ;
String provider;
String value1;
String value2;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Getting LocationManager object
    locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);        

    // Creating an empty criteria object
    Criteria criteria = new Criteria();

    // Getting the name of the provider that meets the criteria
    provider = locationManager.getBestProvider(criteria, false);


    if(provider!=null && !provider.equals("")){

        // Get the location from the given provider 
        Location location = locationManager.getLastKnownLocation(provider);


        locationManager.requestLocationUpdates(provider, 20000, 1, this);


        if(location!=null)
            onLocationChanged(location);
        else
            Toast.makeText(getBaseContext(), "Location can't be retrieved", Toast.LENGTH_SHORT).show();

    }else{
        Toast.makeText(getBaseContext(), "No Provider Found", Toast.LENGTH_SHORT).show();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
public void onLocationChanged(Location location) {
    // Getting reference to TextView tv_longitude
    TextView tvLongitude = (TextView)findViewById(R.id.tv_longitude);

    // Getting reference to TextView tv_latitude
    TextView tvLatitude = (TextView)findViewById(R.id.tv_latitude);

    // Setting Current Longitude
    tvLongitude.setText("Longitude:" + location.getLongitude());

    // Setting Current Latitude
    tvLatitude.setText("Latitude:" + location.getLatitude() );

    value1 = tvLongitude.getText().toString();
    value2 = tvLatitude.getText().toString();

    // saveClicked();

    SaveClicked2();




}

public void SaveClicked2() {

    try{

    File file = new File("/sdcard/Sree.txt");
    file.createNewFile();
    FileOutputStream fOut = new FileOutputStream(file);
     OutputStreamWriter out = new OutputStreamWriter(fOut);
     out.append(value1);
     out.append(value2);
     out.close();

     Toast.makeText(getBaseContext(),
                "Done writing values to textfile",
                Toast.LENGTH_SHORT).show();

    }
    catch(Exception e){

        Toast.makeText(getBaseContext(), e.getMessage(),
                Toast.LENGTH_SHORT).show();



    }







}

private void saveClicked() {



    try{
        OutputStreamWriter out=
                new OutputStreamWriter(openFileOutput(STORETEXT, 0));
        out.write(value1);
        out.write(value2);
        out.close();

        Toast
    .makeText(this, value1, Toast.LENGTH_LONG)
    .show();

    }
    catch(Throwable t){
        Toast.makeText(this, "Exception: "+ t.toString(), Toast.LENGTH_LONG)
        .show();

    }
}

@Override
public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub      
}

@Override
public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub      
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub      
}}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:30:42+00:00Added an answer on June 13, 2026 at 12:30 am

    If you have the textfile on the SD card, then you can use the following uploading approach to upload the file to your server.

    You will need a script, such as this PHP script called uploader.php

        <?php
    
        $target_path = "H:/www/yourwebsitedirectory.com/"; 
        $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    
        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
        " has been uploaded";
        } else{
        echo "There was an error uploading the file, please try again!";
        }
    
        ?>
    

    Then in your java you can have an Uploader function like this:
    Make sure to fill in your proper exception handling, and you will need to grab the HTTPClient libraries.

          public static void Uploader(File fname, String fpath) {
              try {
              DefaultHttpClient httpclient = new DefaultHttpClient();
              httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    
              String postURL = "http://www.yourwebsite.com/uploader.php";
              HttpPost httppost = new HttpPost(postURL);
    
              // the boundary key below is arbitrary, it just needs to match the MPE so it can decode multipart correctly
              httppost.setHeader("Content-Type", "multipart/form-data; boundary=--32530126183148");
              MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, "--32530126183148", Charset.forName("UTF-8"));
        try {
            mpEntity.addPart("uploadedfile",    new FileBody((fname), "application/txt"));
            mpEntity.addPart("MAX_FILE_SIZE",   new StringBody("100000"));
    
        } catch (Exception e1) {
        } 
              httppost.setEntity(mpEntity);
              HttpResponse response;
              try {
                  response = httpclient.execute(httppost);
                  HttpEntity resEntity = response.getEntity();
                  if (resEntity != null) {
                      resEntity.consumeContent();
                  }
              } catch (ClientProtocolException e) {
              } catch (Exception e) {
              }
              httpclient.getConnectionManager().shutdown();
              } catch (Throwable e) {
                  try {
                  } catch (Throwable e1) {
                  }
              }
          }
    

    Call the function like this:

        File tmpDir = new File(android.os.Environment.getExternalStorageDirectory(),"Directory of your file");
        File fname = new File(tmpDir, filesnameonSD);
        Uploader(fname);
    

    And to test your PHP script, you can use a webpage with the following simple HTML form

      <form enctype="multipart/form-data" action="uploader.php" method="POST">
      <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
      Choose a file to upload: <input name="uploadedfile" type="file" /><br />
      <input type="submit" value="Upload File" />
      </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to access the values of latitude and longitude of one class in
I want every node to have a ipaddress string, latitude and longitude values. Also
I have a string of data latitude,longitude,location stored as an NSString. I want to
i am trying to capture longitude and latitude values from android phone.i am able
I have a set of points that have latitude and longitude values and I
The problem is like this: I am retrieving latitude and longitude from a point
I was wondering how to convert latitude and longitude values of CLLocationCoordinate2D to numbers
I have this function that is trying to return the latitude and longitude as
my app needs to store latitude and longitude values parsed from XML into Core
I have latitude and longitude columns in my table. I'm currently storing latitude with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.