コピーペースト機能を実装するための効果的かつ効率的なアプローチを探しています。ClipBoardManager クラスを使用してこれを達成するにはどうすればよいですか。どこでも、クリップ データを使用してテキストをコピーする方法が示されています。ファイルまたはフォルダーをコピーしたい。前もって感謝します
1147 次
2 に答える
-1
ClipboardManager myClipboard;
myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
データのコピー
ClipData myClip;
String text = "hello world";
myClip = ClipData.newPlainText("text", text);
myClipboard.setPrimaryClip(myClip);
データの貼り付け
ClipData abc = myClipboard.getPrimaryClip();
ClipData.Item item = abc.getItemAt(0);
String text = item.getText().toString();
于 2015-04-08T12:29:46.010 に答える
-2
この Android ガイドをご覧になることをお勧めします。
http://developer.android.com/guide/topics/text/copy-paste.html
ファイルをコピーして貼り付けたいので、Java 標準 I/O を使用する必要があります
ファイルをある場所から別の場所にコピーする方法は次のとおりです。
private void copyFile(String inputPath, String inputFile, String outputPath) {
InputStream in = null;
OutputStream out = null;
try {
//create output directory if it doesn't exist
File dir = new File (outputPath);
if (!dir.exists())
{
dir.mkdirs();
}
in = new FileInputStream(inputPath + inputFile);
out = new FileOutputStream(outputPath + inputFile);
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());
}
}
于 2015-04-08T12:15:48.810 に答える