我正在一个服务器上读取客户端发送的数据,但是大小不知道我也不能更改客户端发送大小.
我想从客户端读取数据,直到它阻塞并等待服务器的响应.我尝试过使用available(),它有时会起作用,但有时即使流中有一些数据,它也会返回零.
while((len = in.available()) != 0)
in.read(b,0,len);
Run Code Online (Sandbox Code Playgroud)
有没有办法在Java中这样做?我知道异步方法,但从未尝试过,所以如果有人可以提供一个简短的例子.
我试图将包含2-3个整数(例如:1 2 3)的一个文本文件("1.txt")的内容复制到另一个文本文件("2.txt")但是我收到以下错误在编译时
import java.io.*;
class FileDemo {
public static void main(String args[]) {
try {
FileReader fr=new FileReader("1.txt");
FileWriter fw=new FileWriter("2.txt");
int c=fr.read();
while(c!=-1) {
fw.write(c);
}
} catch(IOException e) {
System.out.println(e);
} finally() {
fr.close();
fw.close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
命令提示符:-
C:\Documents and Settings\Salman\Desktop>javac FileDemo.java
FileDemo.java:20: error: '{' expected
finally()
^
FileDemo.java:20: error: illegal start of expression
finally()
^
FileDemo.java:20: error: ';' expected
finally()
^
FileDemo.java:27: error: reached end of file while parsing
}
^
4 errors
Run Code Online (Sandbox Code Playgroud)
但是在检查代码时,我发现finally()块已正确关闭.
如何检查给定字符串是否包含非数字字符,示例:
x11z returns > 0
x$1 also returns > 0
1111~ also returns > 0
Run Code Online (Sandbox Code Playgroud)
我的意思是说不是之间的一切0-9.我看到类似的线程,但没有他们谈论"非0-9",除了他们显示它a-z或A-Z.
我收到错误..
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at Reverse.main(Reverse.java:20).
Run Code Online (Sandbox Code Playgroud)
语法没有错,所以我不确定为什么编译时会出错?
public class Reverse {
public static void main(String [] args){
int i, j;
System.out.print("Countdown\n");
int[] numIndex = new int[10]; // array with 10 elements.
for (i = 0; i<11 ; i++) {
numIndex[i] = i;// element i = number of iterations (index 0=0, 1=1, ect.)
}
for (j=10; j>=0; j--){ // could have used i, doesn't matter.
System.out.println(numIndex[j]);//indexes should print in reverse order from here but it throws an exception? …Run Code Online (Sandbox Code Playgroud) 我一直在尝试创建一个可以读取两种不同类型的NFC标签的应用程序.一个应该是HCE-IsoDep,在Nexus 5上模拟,一个是Ndef-tag.我遇到了一个小问题:
我设法读取两种类型的标签,但不是我想要的方式.Ndef标签完全没问题.当我尝试阅读我遇到问题的HCE标签时.我只能在手机打开时读取标签,我模拟标签打开(屏幕打开,但锁定打开).每当我解锁屏幕时,它就不会再进行交互了,据我所知,它试图反射.
如果我试图在没有它的情况下onNewIntent直接进行操作onTagDiscovered,那么在HCE设备被锁定和解锁时它都可以工作,但是我无法读取Ndef标签.在logcat中,我收到消息:NfcService LLCP Activation Message当我解锁时读取HCE标签.
当锁定我收到消息:NativeNfcTag Connect to a tag with a different handle(在此之前,我得到:audio_hw_primary select_devices: out_snd_device(2: speaker) in_snd_device(0: ))
我的代码如下:
public class NfcReader extends Activity implements OnMessageReceived {
private static String TAG = NfcReader.class.getSimpleName();
private Button sendButton;
private ProgressBar callProgress;
private NfcAdapter nfcAdapter;
private PendingIntent pIntent;
private IntentFilter[] writeTagFilters;
private String[][] mTechLists;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView dateView = (TextView) findViewById(R.id.dateTextView);
nfcAdapter = …Run Code Online (Sandbox Code Playgroud) 我有一个代码,使用以下代码将具有灰色的位图转换为黑色和白色的位图:
// scan through all pixels
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
// get pixel color
pixel = bitmap.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
int gray = (int) (0.2989 * R + 0.5870 * G + 0.1140 * B);
// use 128 as threshold, above -> white, below -> black
if (gray > 128)
gray = 255;
else …Run Code Online (Sandbox Code Playgroud) 这是一个脚本,它从文件的replace.txt中读取单词并显示每行中每个单词的输出,但我想在一行中显示所有输出.
#!/bin/sh
echo
echo "Enter the word to be translated"
read a
IFS=" " # Set the field separator
set $a # Breaks the string into $1, $2, ...
for a # a for loop by default loop through $1, $2, ...
do
{
b= grep "$a" replaced.txt | cut -f 2 -d" "
}
done
"replacement.txt"文件的内容如下:
hllo HELLO m AM rshbh RISHABH jn JAIN hw HOW ws WAS ur YOUR dy DAY
这个问题不适合我的问题,我只需要帮助就可以将脚本的输出放在一行中.
我有一个用户和一个朋友表.具有用户详细信息的用户和朋友拥有用户的朋友.这是用户表的架构..
create table smsusers(
id varchar(60),
password varchar(50) not null,
fname varchar(30) not null,
lname varchar(30),
mailid varchar(50) not null,
gender varchar(10) not null,
primary key(id)
);
Run Code Online (Sandbox Code Playgroud)
和朋友表..
create table friends_list(
friend_of varchar(60) NOT NULL,
friends_id varchar(60) NOT NULL,
friendship_status varchar(30),
friendship_date timestamp NOT NULL,
primary key(friend_of,friends_id),
foreign key(friend_of) references smsusers(id)
ON DELETE CASCADE ON UPDATE CASCADE);
Run Code Online (Sandbox Code Playgroud)
用户照片
create table profile_pic(pic_id varchar(200),profile_pic_path varchar(1000),small_pic_path varchar(1000),
adddate varchar(100),userid varchar(60),foreign key(userid) references smsusers(id) ON DELETE CASCADE ON UPDATE CASCADE,
primary key(pic_id));
Run Code Online (Sandbox Code Playgroud)
在这里,我想和朋友一起取朋友的随机5朋友
我试过这个查询 …
我.sql在子文件夹中有很多文件.我现在手动打开它们,搜索OLDSERVERNAME并替换它NEWSERVERNAME(我正在进行迁移).必须有一种更快的方法来做到这一点.我尝试使用FART,但我想我做得不对.
这是我试过的(在主文件夹中):
fart -i -p -c *.sql OLDSERVERNAME NEWSERVERNAME
Run Code Online (Sandbox Code Playgroud)
我可以为此目的使用unix实用程序吗?
我已经按照使用EMR控制台上的说明设置了SSH隧道ssh -i ~/SparkTest.pem -ND 8157 hadoop@ec2-52-1-245-67.compute-1.amazonaws.com。我还按照说明设置了FoxyProxy。
我可以在上访问Hadoop ResourceManager http://master-public-dns-name:8088/,并且可以看到我的应用程序正在运行。
单击任何应用程序的主URL或任何节点HTTP URL都将导致“问题加载页面”,其中SSH隧道提供以下输出channel 2: open failed: connect failed: Connection refused。
我应该改用YARN ResourceManager吗?在哪里可以找到该网址?设置代理和SSH隧道时,是否有某种配置步骤会以某种方式错过?
干杯。
grep ×3
java ×3
android ×2
bash ×2
amazon-ec2 ×1
amazon-emr ×1
apache-spark ×1
arrays ×1
bitmap ×1
filereader ×1
filewriter ×1
for-loop ×1
hadoop ×1
hce ×1
image ×1
mysql ×1
nfc ×1
replace ×1
reverse ×1
sql ×1
ssh ×1
threshold ×1
unix ×1