> Yes, it would be great to see how you're doing the load/save. I started
> out trying to load the actual bytes into memory, but it never quite worked
> (never got past the load screen). Then changed approach to use loadUri and
> that worked great.
>
> Hi Mark, here attached is my WebAppInterface Java file that does all the
saving
With your settings, are you able to save to an external drive?
>
I haven't tried yet but I'm curious, too. I'll let you know soon
>
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/8da04c9b-8450-4269-b066-aba425274be0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
package com.tw.btc.tw;
import android.content.Context;
import android.os.Environment;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.widget.Toast;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class WebAppInterface {
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
@JavascriptInterface
public void saveFile(String filename, String data) {
/* String filename = "index.html";
FileOutputStream outputStream;
try {
outputStream = mContext.openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(data.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}*/
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOCUMENTS);
if(!path.exists()) {
path.mkdirs();
}
InputStream in = null;
OutputStream out = null;
try {
String outputPath = String.valueOf(path) + "/tw-backup";
String inputFile = String.valueOf(path) + "/index.html";
String outputFile = String.valueOf(path) + "/tw-backup/index";
//create output directory if it doesn't exist
File dir = new File (outputPath);
if (!dir.exists())
{
dir.mkdirs();
}
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
in = new FileInputStream(inputFile);
out = new FileOutputStream(outputFile + "-backup-" + ts + ".html");
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
in.close();
in = null;
// write the output file (You have now copied the file)
out.flush();
out.close();
out = null;
} catch (FileNotFoundException fnfe1) {
Log.e("tag", fnfe1.getMessage());
}
catch (Exception e) {
Log.e("tag", e.getMessage());
}
File f = new File(path + File.separator + "index.html");
String newfilename = String.valueOf(path) + "/index.html";
//File f = new File(newfilename);
if (!f.getParentFile().exists()) {
f.getParentFile().mkdirs();
}
try {
int one = (int) (((double) data.length()) * 0.01d);
int s = 0;
BufferedWriter w = new BufferedWriter(new FileWriter(newfilename));
do {
int e = data.indexOf(10, s);
if (e == -1) {
e = data.length();
}
w.write(data, s, e - s);
w.newLine();
s = e + 1;
if (s > one) {
one += one;
}
} while (s < data.length());
w.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
}