How do you read a string from DropBox and output it.

Discussion in 'Plugin Development' started by SleepyDog, Oct 19, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    rbrick

    Just use Java's NIO to download the file and then read it from there
    Code:java
    1. try {
    2. URL website = new URL("url here");
    3. ReadableByteChannel rbc = Channels.newChannel(website.openStream());
    4. FileOutputStream fos = new FileOutputStream(new File(this.getDataFolder(),"file name here"));
    5. fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
    6. } catch(Exception ex) {
    7. ex.printStackTrace();
    8. }
     
  2. Offline

    SleepyDog

    Where will it save it to?
     
  3. Offline

    rbrick

    SleepyDog The plugin data folder so /plugins/YourPluginName/file name
     
  4. Offline

    SleepyDog

    It downloaded but the content looked like this:
    [​IMG]
     
  5. Offline

    rbrick

  6. Offline

    SleepyDog

  7. Offline

    Dudemister1999

    SleepyDog Woo, I'm alive again! Still having problems?
     
  8. Offline

    rbrick

    SleepyDog This is what i use
    Code:java
    1. // f is the file you downloaded so new File(getDataFolder(), "filename"); or where ever you saved it.
    2. try {
    3. Scanner scanner = new Scanner(new FileInputStream(f));
    4. while(scanner.hasNext()) {
    5. String line = scanner.nextLine();
    6. // The line is the text.
    7. }
    8. } catch (IOException ex) {
    9. ex.printStackTrace();
    10. }
     
  9. Offline

    SleepyDog

    I don't understand, can you read this similar to the config or will it need more code?
     
Thread Status:
Not open for further replies.

Share This Page